-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGetandUseProxy.py
More file actions
26 lines (23 loc) · 814 Bytes
/
GetandUseProxy.py
File metadata and controls
26 lines (23 loc) · 814 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import requests
from bs4 import BeautifulSoup
from random import choice
def GetProxy():
url = 'https://www.sslproxies.org'
r = requests.get(url)
soup = BeautifulSoup(r.content, 'html5lib')
return {'https': choice(list(map(lambda x: x[0]+':'+x[1],list(zip(list(map(lambda x: x.text, soup.find_all('td')[::8])), (map(lambda x: x.text, soup.find_all('td')[1::8])))))))}
def UseProxy(url):
while True:
try:
proxy = GetProxy()
r = requests.get(url,proxies=proxy,timeout=5)
if r.status_code == 200:
print('Çalışan proxy = ', proxy)
break
except:
print('Bu proxy denendi ancak çalışmıyor : ', proxy)
pass
return r
url = 'https://www.youtube.com/'
x = UseProxy(url)
print(x.text)