一款好用的工具fake-useragent及浏览器代理池

时间:2024-02-24 07:10:43

import requests
from lxml import etree
import random
from fake_useragent import UserAgent

ua=UserAgent()
uas=[]
for i in range(5):
uas.append(ua.random)   #生成随机useragent
print(uas)
for i in range(5):
this_ua=random.choice(uas)   #从uas中随机选择一个

url=\'https://ie.icoa.cn/\'
head={\'user-agent\':this_ua}
res=requests.get(url,headers=head)
res.encoding=\'utf-8\'
root=etree.HTML(res.text)
ua_rst=root.xpath(\'//table[@class="zebra"]/tr/td/i/text()\')
print(ua_rst)