关于python3种xpath采集网页与加载本地页面结果不一致

Fuoluo 2021-04-09 07:21:46
from lxml import etree
import requests
url='https://tieba.baidu.com/f/search/res?isnew=1&kw=&qw=%C8%EB%C8%BA&un=&rn=10&sd=&ed=&sm=1&only_thread=1&pn=0'
response=requests.get(url)
content=response.text
print(content)
html=etree.HTML(content)
pics=html.xpath('//img[@class="p_pic"]/@original')
print(pics)
for pic in pics:
print(pic)

我这样去采集匹配 结果是空的,但是我吧content打印出来然后放a.html里面用这种方式可以正常匹配出来是什么原因啊,真是懵了
from lxml import etree
f=open('./a.html','rb')
content=f.read()
html=etree.HTML(content)
pics=html.xpath('//img[@class="p_pic"]/@original')
for pic in pics:
print(pic)
...全文
212 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

37,719

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧