我正在嘗試從博彩網站進行一些網絡抓?。鹤鳛檫^程的一部分,我必須點擊左側“收藏夾”部分下的不同按鈕來選擇不同的比賽。我們以 ENG Premier League 按鈕為例。我將按鈕標識為:XPath 為://*[@id="SportMenuF"]/div[3],ID 為 91。我點擊按鈕的代碼如下:from selenium import webdriverfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as ECchrome_path = "C:\Python27\Scripts\chromedriver_win32\chromedriver.exe"driver = webdriver.Chrome(chrome_path)driver.get("URL Removed")content = driver.find_element_by_xpath('//*[@id="SportMenuF"]/div[3]')content.click()不幸的是,我在運行腳本時總是收到此錯誤消息:"no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="SportMenuF"]/div[3]"}" 我嘗試了不同的標識符,例如 CCS Selector、ID 以及如上例所示的 Xpath。我也嘗試使用等待和顯式條件。這些都沒有奏效。我還嘗試從網站上抓取一些值,但沒有成功:from selenium import webdriverfrom selenium.webdriver.common.by import Bychrome_path = "C:\Python27\Scripts\chromedriver_win32\chromedriver.exe"driver = webdriver.Chrome(chrome_path)driver.get("URL removed")content = driver.find_elements_by_class_name('price-val')for entry in content: print entry.text同樣的問題,什么都不顯示。該網站嵌入了來自不同網站的 iframe。這可能是我問題的原因嗎?我也嘗試直接從 iframe URL 中抓取,但也沒有用。我將不勝感激任何建議。
添加回答
舉報
0/150
提交
取消