An easy to use tool fake-useragent and browser agent pool

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

UserAgent = UA ()
UAS = []
for I in Range (. 5):
uas.append (ua.random) # generates a random userAgent
Print (UAS)
for I in Range (. 5):
this_ua = The random.choice (UAS) # randomly selecting one from 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)

Guess you like

Origin www.cnblogs.com/tiankong-blue/p/11595016.html