【发布时间】:2014-06-30 07:43:01
【问题描述】:
我正在学习使用 mechanize 解析数据,但我在脚本中遇到了问题:
脚本 1
import mechanize
myBrowser = mechanize.Browser()
myBrowser.open("http://realpython.com/practice/aphrodite.html")
print myBrowser.response().get_data()
脚本 2
import mechanize
myBrowser = mechanize.Browser()
htmlPage = myBrowser.open("http://realpython.com/practice/aphrodite.html")
print htmlPage.get_data()
现在两个脚本的差异很小。首先,myBrowser.open() 没有分配给一个变量,而在第二个中它被分配给一个名为 htmlPage 的变量。现在的问题是,据我所知,您需要使用响应方法和 get_data 之类的响应方法来获取网页的数据。但在我的第二个脚本中,我没有使用响应方法,而是直接使用 get_dat() 方法,如果我在第二个脚本中使用响应,则会出错。为什么会这样?
【问题讨论】:
标签: python python-2.7 mechanize mechanize-python