Я написал следующее на python с использованием модуля mechanize для распечатки HTML-кода из списка URL:
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()
Однако я получаю следующую ошибку в оболочке python:
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()?)
Что я делаю не так?Ура!