第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

從側(cè)邊欄小部件 selenium python 中抓取評(píng)論

從側(cè)邊欄小部件 selenium python 中抓取評(píng)論

海綿寶寶撒 2024-01-04 17:23:09
我正在嘗試練習(xí)從 booking.com 抓取評(píng)論。我隨機(jī)選擇一家酒店并讓 selenium 獲取元素,然后嘗試定位以獲取來自 BeautifulSoup 的評(píng)論,如下所示,但結(jié)果沒有返回任何數(shù)據(jù)。我可以給我一些建議嗎?出了什么問題以及如何解決?from selenium import webdriverfrom bs4 import BeautifulSoupdriver = 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")
查看完整描述

1 回答

?
繁星coding

TA貢獻(xiàn)1797條經(jīng)驗(yàn) 獲得超4個(gè)贊

您必須將焦點(diǎn)切換到打開的新選項(xiàng)卡。你可以使用


driver.switch_to.window(driver.window_handles[1])

這是最終的代碼:


from selenium import webdriver

from bs4 import BeautifulSoup

import time


driver = webdriver.Chrome()

driver.get("https://booking.com")


time.sleep(2)

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

time.sleep(3)

driver.switch_to.window(driver.window_handles[1])

soup = BeautifulSoup(driver.page_source,"html.parser")


containers = soup.find_all("span", {"class": "c-review__body"})


for span in containers:

    print(span.text)

輸出:


“The location is great just few minutes walk to the beach”

“The entire experience was flawless. This is the most beautiful villa I've ever stayed in, let alone, seen. The staff were outstanding and so friendly and professional. The private chefs that cooked breakfast in our Villa was amazing, and SO well pri…

“The staff were great and it was very easy to order meals and have them prepared at a very reasonable price.”

“The villa is spacious and airy with a large private pool.

Bedrooms are large each with their own bathroom facilties.

The staff go above and beyond to make your stay as comfortable as possible.”

“Excellent , friendly helpful staff

Beautiful patio, garden and pool

Very spacious villa 

Fast laundry service

Decorate the villa and bath with flowers for my wife’s birthday ”

“We loved almost everything about Eden Residence from the location, the quality of the villa, the staff, the cost and the room service (cooks came and prepared meals at the cost to buy groceries plus 15%).

The staff are super friendly and we felt ext…

“Great accomodation. Lots of space. Great pool. Good service”

“Everything! The spacious living room, big toilet, beautiful surroundings. Not to forget, fantastic service by all the staff! Sampai jumpa lagi semuanyaaa ????”

“Staff were exceptional. They went above and beyond to meet our needs at all hours of the day/night. Great, convenient location. Large spacious rooms all each with their own bathroom/ensuite. Pool was amazing. Staff cooked traditional suckling pig fo…

“Luxury Villa

Excellent friendly staff

Private pool

Ocean View sunsets from rooftop 

Walking distance to beach”


查看完整回答
反對(duì) 回復(fù) 2024-01-04
  • 1 回答
  • 0 關(guān)注
  • 221 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)