简体   繁体   中英

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

I'm trying to scrape date from Booking*com using BeautifulSoup, but find() returns nothing

I want to get the price of a hostel listed first on Booking*com search result page

The HTTP response is populated fine, and I succeeded to get some tags from the page, but can't retrieve the desired one.

I've tried out in several patterns of argument, but the results are the same;

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

Here's the entire code;

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") )

I expected the div tag including ¥2,275, however it returns None.

Add User-Agent while requesting the page.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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