在python,selenium,Win 7下工作,我想點擊sowcomment
按鈕後就可以點擊位於這個webPage,由wait
處理,然後我想點擊showmore Comments
按鈕來查看更多評論以便刮掉更多評論。第一個按鈕後,我可以提取評論。如何使用硒python3單擊一個網頁上的第二個按鈕?
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
import selenium.common.exceptions
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
import selenium.webdriver.support.ui as UI
driver = webdriver.Firefox()
driver.get("http://www.aljazeera.com/news/2016/07/erdogan-west-mind-business-160729205425215.html")
wait = UI.WebDriverWait(driver, 10)
next_page_link = wait.until(
EC.element_to_be_clickable((By.ID, 'showcomment')))
next_page_link.click()
wait = UI.WebDriverWait(driver, 20)
next_page_link2 = wait.until(
EC.element_to_be_clickable((By.LINK_TEXT, 'Show more comments')))
next_page_link2.click()
v = driver.find_elements_by_class_name('gig-comment-body')
print(v)
for h in v:
print(h.text)
,但第二個按鈕是無法點擊,而給予例外:
selenium.common.exceptions.TimeoutException:
問題是什麼?
你能在這裏這個鏈接分享HTML?或者你是否嘗試過其他一些定位器?或者嘗試使用'By.PARTIAL_LINK_TEXT' .. –
@SaurabhGaur對於HTML,我給出了上面的鏈接,你可以去。我也嘗試過其他選擇器,但都是徒勞的。 – Ali
這次我不能看到HTML,因爲我不是PC,這就是爲什麼我要告訴你在這裏分享鏈接HTML .. –