问题
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