Raymont
Raymont

Reputation: 293

Extract text from webpage with ChromeDriverManager (Python)

I need to get the core question asked on this page and so far this is the code I have used. The problem is that it brings me 'to next question' instead of the expected core 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

Upvotes: 1

Views: 358

Answers (1)

Omar Aflak
Omar Aflak

Reputation: 2962

It seems that the question is inside a div that has question as its id. I guess you can do something like:

from selenium.webdriver.common.by import By
element = browser.find_element(By.ID, "question")
print(element.text)

Upvotes: 2

Related Questions