Я хочу войти на сайт (webnovel.com) через Facebook. Вот мой код:
import requests
from bs4 import BeautifulSoup
import re
headers={
'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:73.0) Gecko/20100101 Firefox/73.0'
}
with requests.session() as session:
session.headers.update(headers)
homepage=session.get('https://www.webnovel.com')
loginFb=session.get('https://ptlogin.webnovel.com/login/facebook?appid=900&areaid=1&returnurl=https%3A%2F%2Fwww.webnovel.com%2FloginSuccess&auto=1&autotime=0&source=&ver=2&fromuid=0&target=iframe&option=&logintab=&popup=1&format=redirect', allow_redirects=False)
loginFb2=session.get(loginFb.headers['Location'], allow_redirects=False)
loginFb3=session.get(loginFb2.headers['Location'], allow_redirects=False)
soup=BeautifulSoup(loginFb3.text,'html.parser')
action_url = soup.find('form', id='login_form')['action']
link=re.search(r'https.*',action_url).group()
hexInLink=re.findall(r'%[0-9A-Z]{2,2}',link)
for item in hexInLink:
link=link.replace(item,bytearray.fromhex(item[1:]).decode())
action_url=link
inputs = soup.find('form', id='login_form').findAll('input', {'type': ['hidden', 'submit']})
post_data = {input.get('name'): input.get('value') for input in inputs}
post_data['email'] = 'email'
post_data['pass'] = 'pass'
scripts = soup.findAll('script')
scripts_string = '/n/'.join([script.text for script in scripts])
datr_search = re.search(r'\["_js_datr","([^"]*)"', scripts_string, re.DOTALL)
if datr_search:
datr = datr_search.group(1)
cookies = {'_js_datr' : datr}
r=session.post(action_url, data=post_data, cookies=cookies, allow_redirects=True)
print(r.history[0].url)
Но я перенаправлен на ту же страницу Facebook без входа в систему. Очевидно, что метод запроса POST не принят, но я не знаю, что еще изменить или что Информация для добавления.
Спасибо за помощь