python 爬虫
2019-12-09 本文已影响0人
金泽夕
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"))