我正在尝试使用reuqests登录网站,然后使用bs4在同一会话中解析另一个网址,但我无法这样做。
以下是登录页面的HTML
<pre class="string" id="auth_user_username" name="username" value="" type="text">
<b class="password" id="auth_user_password" name="password" value="" type="password">
<b class="checkbox" id="auth_user_remember" name="remember" value="on" type="checkbox">
<b value="Login" type="submit"></td><td class="w2p_fc">
<b="_next" value="/" type="hidden"><input name="_formkey" value="5f6182fa-1085-491a-8c3e-e69d11fc02f6" type="hidden"><input name="_formname" value="login" type="hidden">
这是我正在尝试的代码段
res = requests.get(base_url)
# This is the form data that the page sends when logging in
login_data = {
'username': 'user1',
'password': '123456',
'submit': 'id',
}
r = res.post(base_url, data=login_data)
page = urllib2.urlopen('https://test-link.aka.automate.com/perf/view?project=' + branchName + '&suites=Automation').read()
soup = BeautifulSoup(page)