gpt4 book ai didi

python mechanize - 可以登录网站,但无法获取 html 的 URL 列表?

转载 作者:行者123 更新时间:2023-12-01 06:10:52 25 4
gpt4 key购买 nike

我使用 mechanize 模块在 python 中编写了以下内容,以便从列表 URL 打印出 HTML:

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

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()?)

我做错了什么?干杯!

最佳答案

这是mechanize.urlopen(s)

或者正如你所说的browser.open(s)

关于python mechanize - 可以登录网站,但无法获取 html 的 URL 列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5984192/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com