我是Python的新手。我想用python编写一个脚本,运行数千个url并保存响应。为了访问这些URL,需要凭据。所以,我已经编写了一个基本的脚本,它可以转到URL并打印响应。当我浏览多个URL时,网站返回多个用户登录的错误。所以,我想登录一次,并运行在同一登录会话中的其他网址。我能用机械汤做吗。你知道吗
这是我的剧本:
import mechanicalsoup
browser = mechanicalsoup.StatefulBrowser()
browser.open("mywebsite1")
browser.select_form('form[action="/login"]')
browser.get_current_form().print_summary()
browser["userId"] = "myusername"
browser["password"] = "mypassword"
response = browser.submit_selected()
browser.launch_browser()
print(response.text)
browser.open("mywebsite2")
print(response.text)
...... so on for all the URLs
如何保存会话?提前谢谢你的帮助
只需保存并加载
session.cookies
:相关问题 更多 >
编程相关推荐