17 lines
702 B
Python
17 lines
702 B
Python
import requests
|
||
|
||
|
||
# 获取代理
|
||
def get_proxy():
|
||
headers = {
|
||
"User-Agent": 'Mozilla/5.0'
|
||
}
|
||
# proxy_url可通过多米HTTP代理网站购买后生成代理api链接,每次请求api链接都是新的ip
|
||
proxy_url = 'http://need1.dmdaili.com:7771/dmgetip.asp?apikey=e2c93cc3&pwd=7e7b4dc0c932350a36142d3ed2cdb878&getnum=1&httptype=1&geshi=1&fenge=1&fengefu=&operate=2&setcity=all&provin=jiangsu'
|
||
aaa = requests.get(proxy_url, headers=headers).text
|
||
# matches = re.findall(r'(\d+\.\d+\.\d+\.\d+):(\d+)', aaa)
|
||
# result = [{'host': match[0], 'port': match[1]} for match in matches]
|
||
# return result
|
||
proxy_host = aaa.splitlines()[0]
|
||
return proxy_host.split(":")
|