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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何點擊延遲加載網(wǎng)頁上的“顯示更多”按鈕

如何點擊延遲加載網(wǎng)頁上的“顯示更多”按鈕

慕田峪9158850 2022-05-24 13:23:14
我正在嘗試單擊網(wǎng)頁上的“顯示更多”按鈕。我寫了這段代碼,但在代碼下方出現(xiàn)錯誤。from selenium import webdriverfrom selenium.webdriver.support.ui import WebDriverWait#Open Chromedriver=webdriver.Chrome(executable_path="C:/Users/chromedriver.exe")web="https://www.expedia.com/Hotel-Search?adults=1&destination=Montreal%2C%20Quebec%2C%20Canada&endDate=2019-09-16&latLong=45.50195%2C-73.56714&localDateFormat=M%2Fd%2Fyyyy&regionId=178288&sort=recommended&startDate=2019-09-15&useRewards=true"driver.get(web)driver.maximize_window()#parse html        html =driver.page_sourcesoup=BeautifulSoup(html,"html.parser")time.sleep(5)WebDriverWait(driver, 5)#click show moreshow_more=driver.find_element_by_link_text('Show More')#Another element is covering the element you are to click.    driver.execute_script("arguments[0].click();", show_more)錯誤:NoSuchElementException: Message: no such element: Unable to locate element: {"method":"link text","selector":"Show More"}起初,我沒有包含最后一行(execute_script ...),但我認為如果我包含該行但仍然相同,它會起作用。任何幫助,將不勝感激。一個額外的問題是,有沒有辦法多次點擊“顯示更多”按鈕?因為我注意到我必須多次單擊才能查找所有酒店列表。
查看完整描述

3 回答

?
慕絲7291255

TA貢獻1859條經(jīng)驗 獲得超6個贊

我會簡單地使用下面的CSS。


button[data-stid='show-more-results']

腳本:


# scroll to the element before clicking

driver.find_element_by_css_selector("button[data-stid='show-more-results']").location_once_scrolled_into_view

# click on the show more button

driver.find_element_by_css_selector("button[data-stid='show-more-results']").click()

截屏:

http://img1.sycdn.imooc.com//628c6bde0001ed9915670467.jpg

查看完整回答
反對 回復(fù) 2022-05-24
?
Helenr

TA貢獻1780條經(jīng)驗 獲得超4個贊

試試: driver.findElement(By.xpath("//span[contains(text(),'Show More')]")).click()



查看完整回答
反對 回復(fù) 2022-05-24
?
牧羊人nacy

TA貢獻1862條經(jīng)驗 獲得超7個贊

在視口中滾動后,您需要多次單擊帶有文本的按鈕Show More并實現(xiàn)此目的,您可以使用以下定位器策略:


代碼塊:


from selenium import webdriver

from selenium.webdriver.common.by import By

from selenium.webdriver.support.ui import WebDriverWait

from selenium.webdriver.support import expected_conditions as EC


chrome_options = webdriver.ChromeOptions()

chrome_options.add_argument("start-maximized")

chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])

chrome_options.add_experimental_option('useAutomationExtension', False)

driver = webdriver.Chrome(options=chrome_options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')

driver.get("https://www.expedia.com/Hotel-Search?adults=1&destination=Montreal%2C%20Quebec%2C%20Canada&endDate=2019-09-16&latLong=45.50195%2C-73.56714&localDateFormat=M%2Fd%2Fyyyy&regionId=178288&sort=recommended&startDate=2019-09-15&useRewards=true")

while True:

    try:

        driver.execute_script("return arguments[0].scrollIntoView(true);", WebDriverWait(driver,20).until(EC.visibility_of_element_located((By.XPATH, "//span[text()='Show More']"))))

        driver.execute_script("arguments[0].click();", WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Show More']"))))

        print("Show More button clicked")

    except:

        print("No more Show More button")

        break

driver.quit()

控制臺輸出:


Show More button clicked

Show More button clicked

Show More button clicked

.

No more Show More button


查看完整回答
反對 回復(fù) 2022-05-24
  • 3 回答
  • 0 關(guān)注
  • 223 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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