[英]Extract text from webpage with ChromeDriverManager (Python)
我需要得到這個頁面上提出的核心問題,到目前為止這是我使用的代碼。 問題是它把我帶到了“下一個問題”而不是預期的核心問題。
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--window-size=1200,850")
driver = webdriver.Chrome(ChromeDriverManager().install())
url = 'http://ipaulgraham.herokuapp.com/'
driver.get(url)
for i in driver.find_elements_by_xpath("//*[contains(text(), 'question')]"):
print(i.text)
--to next question
似乎問題在一個以question
為 id 的 div 中。 我想你可以這樣做:
from selenium.webdriver.common.by import By
element = browser.find_element(By.ID, "question")
print(element.text)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.