python mechanize - can login to site but can't grab html for a list of URLs?
I've written the following in python using the mechanize module in order to print out the HTML from a list URLs:
import mechanize, fileinput
urls = open('F:\Python\url_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()
I'm just getting the following error in the python shell however:
Traceback (most recent call last):
File "F:\Python\test.py", line 20, in <module>
releasenote开发者_如何转开发 = browser.urlopen(s)
File "C:\Python27\lib\site-packages\mechanize\_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()?)
What am I doing wrong? Cheers!
It's mechanize.urlopen(s)
or as you said browser.open(s)
.
精彩评论