簡體   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