使用 ChromeDriverManager 从网页中提取文本 (Python)
Extract text from webpage with ChromeDriverManager (Python)
我需要获取此页面上提出的核心问题,到目前为止,这是我使用的代码。问题是它带给我 'to next question' 而不是预期的核心问题。
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)
我需要获取此页面上提出的核心问题,到目前为止,这是我使用的代码。问题是它带给我 'to next question' 而不是预期的核心问题。
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)