python - 在 BeautifulSoup (Python) 中找不到亚马逊重定向的 url。从哪里获得重定向网址的任何想法?
问题描述
我正在尝试使用亚马逊广告 API 获取亚马逊广告数据。我必须打开一个特定链接:“ https://www.amazon.com/ap/oa?client_id=...&scope=cpc_advertising:campaign_management&response_type=code&redirect_uri=https://.../ ”,将我重定向到一个网址,我可以在其中提供我的登录数据。
为了获得那个重定向 url,我在 Python 中使用 BeautifulSoup。在 Web Inspector 中,我看到重定向 url 位于名称“location”下的响应标头中,但是当使用 BeautifulSoup 调用时,“location”丢失了。
from bs4 import BeautifulSoup
headers = {'user-agent': 'Thats the User Agent I get from the Web Inspector'}
p = requests.get(
'Thats the link from which I wll be further redirected')
login_data = {
'appAction': 'SIGNIN',
'email': '...',
'password': '...'
}
with requests.Session() as s:
url = p.url
r = s.get(url, headers=headers)
soup = BeautifulSoup(r.content, 'html.parser')
login_data['appActionToken'] = soup.find('input', attrs={'name': 'appActionToken'})['value']
login_data['openid.return_to'] = soup.find('input', attrs={'name': 'openid.return_to'})['value']
login_data['prevRID'] = soup.find('input', attrs={'name': 'prevRID'})['value']
login_data['workflowState'] = soup.find('input', attrs={'name': 'workflowState'})['value']
r = s.post(url, data = login_data, headers=headers)
print(r.content)
我们可以从哪里获得重定向网址的任何想法?
解决方案
您自己就是您的应用程序的主人。您必须知道应用程序的重定向 url 并在 Login-with-Amazon 控制台中设置它。您可以在控制台中为每个应用程序设置多个重定向 URL。
就像是:
https://www.yourpage.com/login
http://localhost:8080/login
另请参阅: https ://advertising.amazon.com/API/docs/en-us/setting-up/generate-api-tokens
推荐阅读
- java - How to summarize a object type in swagger?
- php - 无法将管理员类型分配给我的创建管理员命令
- elasticsearch - Painless: Get time difference
- python - DJANGO 将 AJAX 请求中的新结果值渲染到 HTML 页面
- reactjs - React Profiler - 开始分析并重新加载页面?
- matlab - 如果输入数字列表而不是单个数字,则函数返回错误数据
- angular - 在Angular 2中将数据从父视图传递到子视图
- ruby-on-rails - 在 Rails 应用程序中添加具有多个 SMTP 服务器的 ActionMailer
- javascript - 无论数组大小如何,随机获取半个字符串数组
- javascript - 使用 javascript 在小型设备上单击锚链接时使我的下拉菜单崩溃