1

I want to copy a text from a website and store it into a variable so I can add it to a dictionary later. I wanted to know how do I accomplish it?

Here is my source code:

from selenium import webdriver

f = webdriver.Firefox()

f.get("http://hi.com")

g = f.find_element_by_tag_name('h1').getText()

print g 
1
  • See if this helps Commented Jun 29, 2015 at 21:23

1 Answer 1

1

What type of text you need to copy from web page?

You need to locate webelement of text you need to capture and simply use getText() on it.

String text = driver.findElement(By.id("some id")).getText();

Sign up to request clarification or add additional context in comments.

3 Comments

Say I want to print get the text " This Site Is Under Construction and Coming Soon." and save it into a variable, from hi.com. I tried the method suggested by you and it didn't work.
Try this - String text = driver.findElement(By.xpath("//*[@id='mid']/h1")).getText();
inpython = driver.find_element_by_xpath("your-xpath").text

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.