繁体   English   中英

无法从Booking * com使用BeautifulSoup find()获得所需的标签

[英]Can't get the desired tag with BeautifulSoup find() from Booking*com

我正在尝试使用BeautifulSoup从Booking * com抓取日期,但是find()什么也没有返回

我想获取在Booking * com搜索结果页面上首先列出的旅馆的价格

HTTP响应填充良好,我成功地从页面中获取了一些标签,但无法检索到所需的标签。

我已经尝试了几种论证模式,但是结果是相同的。

find(class_="bui-price-display__value") 
find("div", class_="bui-price-display__value") 
find("div",{"class":"bui-price-display__value"})

这是整个代码;

import requests
from bs4 import BeautifulSoup

request = requests.get ("https://www.booking.com/searchresults.ja.html?checkin_year=2019&checkin_month=9&checkin_monthday=3&checkout_year=2019&checkout_month=9&checkout_monthday=4&no_rooms=1&group_adults=1&group_children=0&from_sf=1&ac_position=0&ac_langcode=ja&dest_id=434312&dest_type=hotel&search_selected=true&ac_suggestion_list_length=1&ac_suggestion_theme_list_length=0&selected_currency=JPY")
soup = BeautifulSoup(request.text)
print( soup.find(class_="bui-price-display__value") )

我希望div标签包含¥2,275,但是它返回None。

请求页面时添加User-Agent

import requests
from bs4 import BeautifulSoup
headers = {'User-Agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36'}
request = requests.get ("https://www.booking.com/searchresults.ja.html?checkin_year=2019&checkin_month=9&checkin_monthday=3&checkout_year=2019&checkout_month=9&checkout_monthday=4&no_rooms=1&group_adults=1&group_children=0&from_sf=1&ac_position=0&ac_langcode=ja&dest_id=434312&dest_type=hotel&search_selected=true&ac_suggestion_list_length=1&ac_suggestion_theme_list_length=0&selected_currency=JPY",headers=headers)
soup = BeautifulSoup(request.text,'html.parser')
print(soup.find(class_="bui-price-display__value").text)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM