0

我迷路了:)

目标是登录到使用 OAuth2 的网站。但是,我需要运行的部分没有与之关联的 API。所以我需要登录,只需使用用户名和密码,然后导航到有问题的页面并进行屏幕抓取以获取我的数据。

我确定问题不在于它位于此键盘上的网站。但是我已经搜索了示例并尝试了一大堆猜测,但没有任何效果

我们将不胜感激地接受帮助。

import sys
import requests
import oauth2 as oauth

r = requests.get(logon_url)
consumer = oauth.Consumer(key=user, secret=password)
client = oauth.Client(consumer)
resp, content = client.request(r.url, "GET")
token_url = resp['content-location']

# At this point i'm lost i'm just guessing on the rest
# the next doesn't give an error but i'm sure it's wrong
resp2, content2 = client.request(token_url, 'GET')

# save the cookie, i do have a cookie but not sure what i have 
auth_token = resp['set-cookie']
4

1 回答 1

1

像很多事情一样,这只是用户错误

让我进入页面的代码非常简单。下面的代码可以解决问题。感谢 Furas 的指点。

    with requests.session() as s1:
         # get login form
         r = s1.get(logon_url)
         # post the username and password
         resp = s1.post(r.url,data=payload)
         # get the admin page
         resp2 = s1.get(page_url)
于 2016-01-23T04:50:26.420 回答