-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_proxy_example.py
48 lines (40 loc) · 1.23 KB
/
get_proxy_example.py
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/python
# -*- coding: utf-8 -*-
# @author: [email protected]
# @date: 2019-3-16
import requests
from bs4 import BeautifulSoup
headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.108 Safari/537.36',
}
def get_proxy():
r = requests.get('http://127.0.0.1:5555/random')
soup = BeautifulSoup(r.text, "lxml")
trs=soup.find("div",id="container").find_all("tr")
for tr in trs[1:]:
IP = tr.find_all("td")[0].get_text()
PORT = tr.find_all("td")[1].get_text()
proxies = {
'http': 'http://' +IP+":"+PORT,
'https': 'https://' +IP+":"+PORT
}
return proxies
def crawl(url, proxy):
print(proxy)
r = requests.get(url,headers=headers, proxies=proxy,verify=False)
if response.status_code == 200:
print('Successfully')
print(response.text)
return r.text
def main():
while True:
for url in ['https://api.ipify.org?format=json','http://www.whatismyip.com']:
try:
proxy = get_proxy()
html = crawl(url, proxy)
print(html)
except:
pass
continue
if __name__ == '__main__':
main()