0

im using the selemium to extract data .i need to select all the text and copy to the variable .but it select all the text but it not copying.any can help this?

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get('https://en.wikipedia.org/wiki/Apple_Inc.')
element=driver.find_element_by_css_selector('body')
all_text=element.send_keys(Keys.CONTROL+'a')
copy=element.send_keys(Keys.CONTROL+'c')
print copy
driver.close()
5
  • I do not know why you are using selenium, but most of the people are using complex solutions (such as selenium) instead of simpler ones (using urllib3 and bs4). Is getting all the elements what you need? I could help you with a simple script without selenium Commented Oct 11, 2018 at 10:16
  • @EDv What exactly do you mean by all the text? Entire html? Commented Oct 11, 2018 at 10:45
  • Why are you scraping wikipedia? That's going to break their ToS. What is it you are trying to do? Commented Oct 11, 2018 at 18:00
  • i know about the bs4 and urllib.but i dont want to use that .i need to select all page like cntrl+a ,and copy that text into a variable @DebanjanB Commented Oct 12, 2018 at 8:48
  • Still not sure about your usecase for which you want to do cntrl+a but if you want to _...copy the text... @Infern0 Answer looks just perfect to cater to your requirement. Let me know if you are looking for something else. Commented Oct 12, 2018 at 9:04

1 Answer 1

3

to get the text

element=driver.find_element_by_id("bodyContent") 
print(element.text)

to get the html content

driver.get('https://en.wikipedia.org/wiki/Apple_Inc.') 
content = driver.page_source

soup = BeautifulSoup(content) 
print soup
Sign up to request clarification or add additional context in comments.

Comments

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.