登陆

数据转换之后,用xpath('//*').extract()可以找到需要的div标签,但是使用xpa

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)

# Python爬虫
十1426 天前1844 次浏览

全部回复(1)我要回复

暂无评论~
  • 取消回复
  • © 2021 Python学习网 苏ICP备2021003149号-1