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

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)

上一篇:获取请求头中User-Agent工具类


下一篇:struts2与struts1整合,java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory