我在下午用机械化模块写下以下文字,以便从URLs清单中删除超文本:
import mechanize, fileinput
urls = open( F:Pythonurl_list.txt )
content = [x.strip() for x in urls.readlines()]
print content
browser = mechanize.Browser()
browser.open("https://login.asp")
browser.select_form(nr=0)
browser[ desc ] = "xxxxx"
browser[ password ] = "xxxxx"
response = browser.submit()
logincheck = response.read()
print logincheck
# now logged into site, loop through the list of urls read in from the text file and print the html for each one:
for s in content:
releasenote = browser.urlopen(s)
# error here, should be releasenote = browser.open(s)
print releasenote.geturl()
print releasenote.info()
print releasenote.read()
然而,我只想到的是,在座标上出现以下错误:
Traceback (most recent call last):
File "F:Python est.py", line 20, in <module>
releasenote = browser.urlopen(s)
File "C:Python27libsite-packagesmechanize\_mechanize.py", line 628, in __getattr__
".select_form()?)" % (self.__class__, name))
AttributeError: mechanize._mechanize.Browser instance has no attribute urlopen (perhaps you forgot to .select_form()?)
我做了什么错误? Cheers!