Python Selenium 'WebDriver' 对象没有属性错误 [英] Python Selenium 'WebDriver' object has no attribute error

查看:83
本文介绍了Python Selenium 'WebDriver' 对象没有属性错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从一个中文网站抓取一些 javascript 生成的内容.我正在使用 Selenium(和 Python),因为我无法直接抓取 javascript 内容.

I'm trying to scrape some javascript-generated content from a Chinese-language website. I'm using Selenium (and Python) since I can't scrape the javascript content directly.

# -*- 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

我收到以下错误:

'WebDriver' object has no attribute 'get_body_text'

事实上,我似乎无法调用 selenium.selenium 类中的任何命令.毫无疑问,我忽略了一些非常明显的事情.提前致谢.

In fact, I can't seem to call any commands in the selenium.selenium class. No doubt I'm overlooking something very obvious. Thanks in advance.

推荐答案

  1. 您只需要from selenium import webdriver.
  2. 执行html= browser.find_element_by_xpath(".//html") 获取页面上的html元素,最大的元素.(您可以通过多种方式执行此操作,并选择任意数量的元素.)
  3. 执行html.text返回页面的文本.
  1. You only need from selenium import webdriver.
  2. Execute html= browser.find_element_by_xpath(".//html") to get the html element on the page, the largest element. (You can do this any number of ways, and select any number of elements. )
  3. Execute html.text to return the text of the page.

.text 是一个 element 对象的方法.第 2 步是将 element 分配给名称 html.

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

这篇关于Python Selenium 'WebDriver' 对象没有属性错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆