随机User Agent
pip install fake_useragent
from fake_useragent import UserAgent
ua=UserAgent()
print(ua.ie)
print(ua.chrome)
print(ua.firefox)
print(ua.safari)
print(ua.opera)
print(ua.random)
获取代理IP
有代理:https://www.youdaili.net/Daili/guonei/
66代理:http://www.66ip.cn/6.html
西刺代理:https://www.xicidaili.com/
快代理:https://www.kuaidaili.com/free/
def get_proxy_ip(page_size=1):
proxy_map_list=list()
for page in range(1,page_size+1):
url="https://www.kuaidaili.com/free/inha/{0}/".format(page)
resp=requests.get(url)
resp.encoding="uft-8"
soup=BeautifulSoup(resp.text,"lxml")
tr_list=soup.find("tbody").find_all("tr")
for tr in tr_list:
proxy_map_list.append({one_proxy_info.attrs.get("data-title"):one_proxy_info.text for one_proxy_info in tr.find_all("td")})
time.sleep(1)
return proxy_map_list
def use_proxy():
url = "http://10.0.0.152/platform-supplier#/account/login"
header={"User-Agent":UserAgent().random}
proxy={"http":"1.196.105.154:9999","https":"1.196.105.154:9999"}
resp = requests.get(url,proxies=proxy,headers=header,timeout=5,verify=False)
resp.encoding = "uft-8"
return resp.text