我正在尝试抓取阿里快递。众所周知,如果检测到抓取尝试,我的 ip 可能会被禁止...这就是为什么我试图用 selenium wire 中的代理隐藏我的 IP,但是当我检查 IP 网站时,它给了我同样的信息IP 就像我不使用代理时一样。这是我的源代码:
from seleniumwire import webdriver
import requests
def gimme_proxy():
orilist = ["104.28.18.46:80","104.31.6.146:80","104.28.4.43:80","136.228.165.138:8080"]
finalist = []
for occurence in orilist:
# finalist.append({"http": occurence, "https": occurence})
finalist.append({ "https": occurence})
for proxy in finalist:
if proxy_try(proxy) == 0:
continue
else:
print("Mission passed !!!!!!!!!!!!!!!!!!!")
print(proxy)
return proxy
def get_page(url,proxy,useragent):
options = {"proxy": proxy}
driver = webdriver.Chrome(seleniumwire_options=options)
driver.header_overrides = {"User-Agent": useragent}
driver.get(url)
return driver.page_source
def proxy_try(proxy):
try:
requests.get("http://google.com",proxies=proxy)
except Exception :
print("iddek fiih")
return 0
else:
print("lqadyya msllka waqila")
return 1
useragent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36'
get_page("https://whatismyipaddress.com/fr/mon-ip",gimme_proxy(),useragent)
提前致谢