import requests
import parsel
#获取网页
base_url='https://tieba.baidu.com/f?ie=utf-8&kw=%E7%BE%8E%E5%A5%B3'
#伪装身份
headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.87 Safari/537.36'}
#获得回应
response=requests.get(base_url,headers=headers)
html_str=response.text
#print(html_str)
html=parsel.Selector(html_str)
#print(html)
title_url=html.xpath('//div').extract()
print(title_url)
© 2021 Python学习网 苏ICP备2021003149号-1