【发布时间】:2012-10-06 06:26:56
【问题描述】:
我正在尝试从一个中文网站上抓取一些 javascript 生成的内容。我正在使用 Selenium(和 Python),因为我无法直接抓取 javascript 内容。
# -*- 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 类中的任何命令。毫无疑问,我忽略了一些非常明显的东西。提前致谢。
【问题讨论】:
-
你用的是什么版本,
2.21.3这个版本没有这个功能 -
你也确定
from selenium.selenium import selenium有效 -
感谢@avasal 的回复!我正在使用 2.25.0。不完全确定
from selenium.selenium import selenium是否在这里工作,但不确定如何从该类导入命令。当然不会抛出错误并看到其他人使用此代码。 -
尝试在 python 提示符中一一执行这些行中的每一行。你会正确地遇到错误
-
不幸的是,在提示符中它仍然会为最后一个命令抛出相同的内容:
AttributeError: 'WebDriver' object has no attribute 'get_body_text'
标签: python selenium attributes web-scraping attributeerror