Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用ChromeDriverManager(Python)从网页中提取文本_Python_Selenium Chromedriver_Driver - Fatal编程技术网

使用ChromeDriverManager(Python)从网页中提取文本

使用ChromeDriverManager(Python)从网页中提取文本,python,selenium-chromedriver,driver,Python,Selenium Chromedriver,Driver,我需要得到这个页面上的核心问题,到目前为止,这是我使用的代码。问题是,它把我带到了“下一个问题”,而不是预期的核心问题 from selenium import webdriver from webdriver_manager.chrome import ChromeDriverManager from selenium.webdriver.chrome.options import Options chrome_options = Options() chrome_options.add_a

我需要得到这个页面上的核心问题,到目前为止,这是我使用的代码。问题是,它把我带到了“下一个问题”,而不是预期的核心问题

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

问题似乎位于id为
question
的div中。我猜您可以执行以下操作:

通过导入从selenium.webdriver.common.by导入 element=browser.find_元素(By.ID,“问题”) 打印(element.text)
回答得很好!谢谢不客气:)