1.requests
import requests
url='http://baidu.com'
headers={
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36"
}
params={}
req = requests.get(url,headers = headers)
content = req.content.decode('utf-8')
2.xpath
# 输出元素html
print(etree.tostring(a,encoding='utf-8').decode("utf-8"))
网友评论