无法使用python请求登录网站

时间:2019-01-13 20:51:06

标签: python web-scraping beautifulsoup python-requests

import requests
from bs4 import BeautifulSoup as soup
import webbrowser
from urllib.request import Request, urlopen
import requests
import urllib
import re
import time
import math ## i know some of the imports are unnecessary, but i just copy paste them everywhere

headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)     AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36'}

j=0
proxies = {'http': "http://213.6.68.78:53281",
           'https': "https://213.6.68.78:53281"}

login_data = {
    'username': 'my_nickname420',
    'password': 'password1234',
    'phone': '' 
}

with requests.Session() as s:
    while(1):
        try:
            s.proxies = proxies
            break
        except:
            print('error in connecting to proxy... ')

    url = "https://www.TOPSECRETSITE.com/login"
    r = s.get(url)
    page_soup = soup(r.content, 'html5lib')
    login_data['_csrf'] = page_soup.find('input', attrs={'name': '_csrf'})    ['value']
    r = s.post(url, data=login_data, headers=headers)
    print(r.content)

当我运行代码时,它给了我一个输出,但是以某种方式我仍然没有连接到站点,它显示我是来宾用户。

以下是登录后通常单击浏览器后单击检查元素时看到的内容

*Form Data 

username: my_nickname420

password: password1234

_csrf: m4beGyaG-CGYiSd2PHSjt3yFyHBsK1YP4GbI

phone: 

如果有帮助,上面还有一些“设置cookie”的事情。

0 个答案:

没有答案