[英]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.