标签:rand 浏览器 this root int 工具 table dom headers
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)
标签:rand 浏览器 this root int 工具 table dom headers
原文地址:https://www.cnblogs.com/tiankong-blue/p/11595016.html