I want to extract all the text in a specific webpage.
In JavaScript the code looks like this:
var webPage = require('webpage');
var page = webPage.create();
page.open('http://phantomjs.org', function (status) {
console.log('Stripped down page text:\n' + page.plainText);
phantom.exit();
});
How can I run page.plainText in Python?
Thanks.
If you want to do that with Selenium, you have to select the "top" element and after the call to getText().
For example, in Python:
driver = webdriver.PhantomJS(executable_path='pathTo/phantomjs')
driver.get('https://en.wikipedia.org/wiki/Selenium_(software)')
el = driver.find_element_by_tag_name('body')
print(el.text)
driver.close()
Try this code:
text = driver.find_element_by_tag_name("body").get_attribute("innerText")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With