Python版本:3.6
IDE:PyCharm
1.解析HTML(这里以www.baidu.com为例)
headers = { 'Connection': 'Keep-Alive', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36' } soup = BeautifulSoup(requests.get("https://www.baidu.com/",headers=headers).content,'lxml')