Send POST data in input form and scrap page, Python, Requests library

痴心易碎 提交于 2019-12-24 09:19:16

问题


I have problem. I dont know how i can send POST data and scrap content of next page. Simple Example for better understanding:

Facebook website of profile recovery with one input: http://m.facebook.com/login/identify?ctx=recover
Input:

<input autocapitalize="off" class="y z ba" id="login_identify_search_placeholder" name="email" autofocus="1" placeholder="Adres e-mail lub numer telefonu" type="text">

I wanna make script, which recover my account, so i wanna send my email to input by POST and scrap next page. My code:

import requests
from BeautifulSoup import BeautifulSoup
Soup = BeautifulSoup
headers = {'User-Agent': 'Mozilla/5.0'}
payload={
"lsd": "AVqS_aom",
"email": "mycorrect email",
"did_submit": "Search"
}

session = requests.Session()
x = session.post('http://m.facebook.com/login/identify?ctx=recover', headers=headers, data=payload)
#print x.content
x.encoding = "utf-8"
parsed = BeautifulSoup(x.content)
print(parsed) #It's print me only started page, not next page with my finded profile. WTF??

回答1:


If the response is another page, I would recommend to use something like BeautifulSoup, to parse html and extract data from it, and also if you need history, you have it x.history, depends on which version of python you are using, you can use BeautifulSoup like: python 3.x: parsed = BeautifulSoup(x.content.decode("utf-8"), "html.parser") python 2.x: parsed = BeautifulSoup(x.content, "html.parser")



来源:https://stackoverflow.com/questions/43167530/send-post-data-in-input-form-and-scrap-page-python-requests-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!