爬取美团酒店,取回的数据和网站位置不一样

imfeijiu 2017-10-20 07:29:37
这个是我爬取的连接http://hotel.meituan.com/item/161066061/?ci=2017-10-20&co=2017-10-21
爬取的位置

抓取的文本应该是价格,但输出的是0


代码是这个

from urllib.request import urlopen
from bs4 import BeautifulSoup
lii=["http://hotel.meituan.com/item/161066061/?ci=2017-10-20&co=2017-10-21","http://hotel.meituan.com/item/5651700/?ci=2017-10-20&co=2017-10-21"]
for ss in lii:
url=urlopen(ss)
soup=BeautifulSoup(url.read(),"lxml")
ui=soup.find_all("span",{"class":"fs26 fc3 pull-left bold"})
score=soup.select("#poiDetail > div > div > div.base-info > div > div.relative")

for name in score:
print(name.get_text())

是抓取的方法不对吗?
...全文
363 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
ZA1025 2020-03-30
  • 打赏
  • 举报
回复
我也遇到了类似的问题,网页中有的内容复制了selector或xpath之后就能导出,有的却是空的。 我爬取的是网易新闻的首页广告。https://news.163.com/
from requests_html import HTMLSession
session = HTMLSession()
url = 'https://news.163.com/'
r = session.get(url)
sel='//*[@id="index2016_wrap"]/div[1]/div[2]/div[2]/div[1]/div/iframe/html/body/a'
results = r.html.xpath(sel)
print(results.html.text)

3,424

社区成员

发帖
与我相关
我的任务
社区描述
其他开发语言 其他开发语言
社区管理员
  • 其他开发语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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