0

一直在寻找和寻找,测试和尝试,阅读和阅读......我不是程序员,不会快速拿起这些东西。

这是我的代码:

import requests

url = 'http://company.page.com/member/index.php' (this url has the form on it)
values = {'username': 'myusernamehere',
          'password': 'mypasswordhere'}

r = requests.post(url, data=values)

# Now you have logged in
url = "http://company.page.com/member/member.php" (this is the resulting url after logging in)

# sending cookies as well
result = requests.get(url, cookies=r.cookies)

print (result.headers)
print (result.text)

我得到错误:

<form action="http://company.page.com/member/index.php" method="post" id="login">
   <h3 class="head">Donor Login</h3>
   <em class="notice"><p class="errors">you must log in</p><br />

网站源代码的图像:(我可以弄清楚如何发布 html 的第一种方法)

网站源代码

4

1 回答 1

1

使用session. 或者不保存cookies。

import requests

s = requests.session() # <--

url = 'http://company.page.com/member/index.php'
values = {'username': 'myusernamehere',
          'password': 'mypasswordhere'}

r = s.post(url, data=values) # session.post instead of requests.post

# Now you have logged in
url = "http://company.page.com/member/member.php" (this is the resulting url after logging in)

result = s.get(url) # Use session.get and do not specify cookies.

print (result.headers)
print (result.text)
于 2013-09-03T18:11:56.700 回答