如何使用python登录网站

时间:2018-02-18 21:50:26

标签: python python-3.x authentication web-scraping python-requests

我正在尝试登录alexa.amazon.com 但我无法做到。我尝试了很多东西,这就是我现在想要使用的东西:

import requests
from bs4 import BeautifulSoup
from lxml import html
import re


payload = {
    "username": "MY_EMAIL", 
    "password": "MY_PASSWORD", 
    "appActionToken": "Taken from the login page"
}

session_requests = requests.session()

login_url = "https://www.amazon.com/ap/signin?showRmrMe=1&openid.return_to=https%3A%2F%2Fpitangui.amazon.com&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.assoc_handle=amzn_dp_project_dee&openid.mode=checkid_setup&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&"

result = session_requests.get(login_url)

tree = html.fromstring(result.text)
authenticity_token = list(set(tree.xpath("//input[@name='appActionToken']/@value")))[0]

result = session_requests.post(
    login_url, 
    data = payload, 
    headers = dict(referer=login_url)
)

url = 'http://alexa.amazon.com/spa/index.html#settings/dialogs'

任何帮助都会很棒。谢谢!

0 个答案:

没有答案