Python Selenium 'WebDriver' Object Has No Attribute Error

I am trying to clear javascript generated content from a Chinese website. I am using Selenium (and Python) as I cannot directly clear the javascript content.

# -*- coding: utf-8 -*- from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.selenium import selenium import time import urllib2 import httplib import urllib import re import base64 browser = webdriver.Firefox() # Get local session of firefox browser.get("http://www...") # Load page (redacted here, but any works) browser.get_body_text() #Attempt to scrape body text 

And I get the following error:

 'WebDriver' object has no attribute 'get_body_text' 

In fact, I cannot name any commands in the selenium.selenium class. Without a doubt, I am observing something very obvious. Thanks in advance.

+4
source share
1 answer
  • You only need from selenium import webdriver .
  • Run html= browser.find_element_by_xpath(".//html") to get the html element on the page, the largest element. (You can do this in any number of ways and select any number of elements.)
  • Run html.text to return the page text.

.text is a method of an element object. Step 2 is to assign the element html name.

+3
source

Source: https://habr.com/ru/post/1439984/


All Articles