我正在尝试练习从 booking.com 抓取评论。我随机选择一家酒店并让 selenium 获取元素,然后尝试定位以获取来自 BeautifulSoup 的评论,如下所示,但结果没有返回任何数据。我可以给我一些建议吗?出了什么问题以及如何解决?
from selenium import webdriver
from bs4 import BeautifulSoup
driver = webdriver.Chrome(executable_path="./driver/chromedriver.exe")
driver.get("https://booking.com")
driver.find_element_by_css_selector("input[class*='sb-searchbox__input']").send_keys("Eden The Residence at The Sea")
driver.find_element_by_css_selector("button[type='submit']").click()
driver.find_element_by_xpath("//span[contains(text(),'Eden The Residence at The Sea')]").click()
soup = BeautifulSoup(driver.page_source,"html.parser")
containers = soup.find_all("div", {"class": "review_list_container"})
reviews = containers[0].find_all("ul")
繁星coding
相关分类