PythonMechanize可以登录到站点,但不能获取URL列表的html?

2024-09-30 02:15:51 发布

您现在位置:Python中文网/ 问答频道 /正文

为了从列表url打印出HTML,我使用python编写了以下代码:

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 shell中得到以下错误:

^{pr2}$

我做错什么了?干杯!在


Tags: theinbrowserurlforreadresponseopen

热门问题