2017-05-08 119 views
0

我想製作腳本,恢復我的帳戶,所以我想通過POST發送我的電子郵件到輸入並用我的帳戶信息(名稱,照片等)報廢下一頁。我的代碼:Facebook的發佈請求和奇怪的(也許加密)輸出?

import requests 
from bs4 import BeautifulSoup 
Soup = BeautifulSoup 


#Parse page, i need "lsd_value" to send POST request 
x = requests.get('http://m.facebook.com/login/identify?ctx=recover') 
x.encoding = "utf-8" 
parsed = BeautifulSoup(x.content, "html.parser") 
print(parsed) 

lsd_value = parsed.find('input', {'name': 'lsd'}) 
output_lsd_value = lsd_value['value'] 
print(lsd_value['value']) 

#POST 
headers = { 
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64; rv51.0) Gecko/20100101 Firefox/51.0" 
} 
payload={ 
"lsd": output_lsd_value, 
"email": "correct facebook_email", 
"did_submit": "Search" 
} 

#Send and print POST request 
session = requests.Session() 
x = session.post('http://m.facebook.com/login/identify?ctx=recover', 
headers=headers, data=payload) 
print "x.content:", x.content 
x.encoding = "utf-8" 
parsed = BeautifulSoup(x.content, "html.parser") 
print"parsed:", parsed 

我的新問題,Facebook需要captcha當我使用此腳本併發送POST請求。但是,當我使用瀏覽器的Facebook不需要captcha ...有可能繞過這個? 輸出上面的腳本:

<?xml version="1.0" encoding="utf-8"?> 
 
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Mechanizm zabezpieczający</title><meta content="origin-when-crossorigin" id="meta_referrer" name="referrer"/><style type="text/css">/*<![CDATA[*/.img{border:0;display:inline-block;vertical-align:top;}i.img u{position:absolute;width:0;height:0;overflow:hidden;}._5whq{border:solid 1px #999;border-top-color:#888;margin:0;}.b ._5whq{padding:3px 3px 4px 0;}.l{background-color:#fff;}.i{background-color:#3b5998;}.j{padding:2px 3px;}.m{padding:4px 3px;}form{margin:0;border:0;}.n{border:solid 2px;cursor:pointer;margin:0;padding:2px 6px 3px;text-align:center;}.p,.i .o,.b a.p,.b .i a.o{background:#f3f4f5;border-color:#ccC#aaa #999;color:#505c77;}.i .p,.o,.b .i a.p,.b a.o,.b a.o:visited{background:#3b5998;border-color:#8a9ac5 #29447E #1a356e;color:#fff;}.n .img{pointer-events:none;}.n{display:inline-block;}.n+.n{margin-left:3px;}.n input{background:none;border:none;margin:0;padding:0;}.p input,.i .o input{color:#505c77;}.i .p input,.o input{color:#fff;}body{text-align:left;direction:ltr;}body,tr,input,textarea,button{font-family:sans-serif;}body,p,figure,h1,h2,h3,h4,h5,h6,ul,ol,li,dl,dd,dt{margin:0;padding:0;}h1,h2,h3,h4,h5,h6{font-size:1em;font-weight:bold;}ul,ol{list-style:none;}article,aside,figcaption,figure,footer,header,nav,section{display:block;}.e #viewport{margin:0 auto;max-width:600px;}.f{background:#dddfe2;}.q{background:#fff;}#page{position:relative;}.k{padding-bottom:4px;padding-top:4px;}.b a,.b a:visited{color:#3b5998;text-decoration:none;}.b a:focus,.b a:hover{background-color:#3b5998;color:#fff;}body,tr,input,textarea,.g{font-size:medium;}/*]]>*/</style></head><body class="b c d e f" tabindex="0"><div class="g"><div id="viewport"><div class="h"><div class="i j" id="header" role="banner"><h1><a href="/home.php"><img alt="facebook" class="k img" height="16" src="http://static.xx.fbcdn.net/rsrc.php/v3/y8/r/k97pj8-or6s.png" width="77"/></a></h1></div></div><div id="objects_container"><div class="f" id="root" role="main"><div class="l m"><form action="http://m.facebook.com/login/identify?ctx=recover" method="post"><input autocomplete="off" name="lsd" type="hidden"/><div class="captcha" id="captcha"><h3>Mechanizm zabezpieczający</h3><div class="divider"></div><input id="captcha_persist_data" name="captcha_persist_data" type="hidden" value="AZkR-mZNlYsAr8-JqaqwdOM7H6UIuRTSexKXf78qVYjItyYI8OOu44pw2HuQ7U2GWX4fe_hU1DI-h6krTZbg_k6jgDfGindy1QfYh-9X3AIsCuFvd2-RLOM9SpEERQO-oKiZ1pSxUUpR3cD__SgsPMETCZ9K_kYgxHl0HXhIBf7PZL-YjLBpEaOtJo7uXskKJmewNa733I0bvY0Sty99H6MK4ooliJyTyv4ISVzbtSnmr6yljhkyBqKzbUksS4pFu1e3kcRH9zpEYbG2eAmFNUgiSy_X8thnbNbErJj3T62XT5h85lWo4_oIlcyGSzQzZU5vwPHGzmRVnQC9YzH0U01zr1Jp4UBLzVXlwia_ylN4d_Zp0YCQHwcAKCx_qhhrSR2TnnB9-XBWueFNMyM8738Y9DWCLzu2gAQf0PA60SSkl66nFOPWq1R9nRL9zJlgXoFnu9tS5Hlqojegbl2kGQKAAtgXr1vRXffnZasjSvUhQg3KUV2mM4f0zE_hGzCOUhpblF9j0wSGvkToHnuFHdwIH1EhlQoe1FoB1PyL85M5t7esEcrtj3X-SsDDhHBLihzNuazMkWxa6zHyZMZqVEwITmihOp-JmHQpRPUXm5uQpJhDhfRkDfKWIpdk4QjhQoJvMe3GqErOeEZOC1I-L7GQt3fwSalDkD_HIAg0N69giVq8XULU10xQRXdRgJB9iXEYvGmy64g74ZbNwN0JahTWJpaimhkticWkYpauEEcgavrRGh8vCUg6hGNfFSnQf8grLyYCyTIvxmenzN07pqaqsUyzxAqAplhgibArYf-zIqFgydBuiao8rF5ipoUG8bLoTv8wFIfvbbdlE_USpy03wQAIxr7kJIABZQw9XpkQpHlAiAv92aDcBxJPMtY0tKHYOObL9RInqln15UB-bxGMDGe61HjqUf9Mxuu7BvUFxj0_GoSgkreHNU12d9fnwKQCdX6Jp4puFbQDO7kavLenIyIYKDuCsIujaHBDr_dsHIdtYoV_9EzPRheXAafeItrIV77nZqg4QxgOTWPAAPTa0VgpzH84pfcHb_xSj7RarUti23E6O33lkBHnUxVk0DaC1Yc36ayM8tT4PsEhPJWDt2EdNX4ng1ZpV6U0RR1w8IEyYE9Ogz3cZdiy_7xd5J7HtSJomAIk3fVLOBHSFQfOSKhZiZFgNU4PyEu7bsT6Rw"/><div>Wpisz tekst poniżej</div><img class="img" src="http://m.facebook.com/captcha/tfbimage.php?captcha_challenge_code=1494247049-ddf639c529903bb163f48fdc3f6ade78&amp;captcha_challenge_hash=AZmWSZrt6gRWT5alzyKkG5m-QDHLnIAVObKZ01W2Q0ljoCeRAAOVKSrJqHVq0MBoNgwHHp-F3_kKCUHwasEfYD7YlXm73aSkdvMbC2EZ4P5cUAemRlmbC-nt0hOLfWg-ydFzPxzbd3fbPUtCCCmIrsmZAeSeOzR8euoKboldbmjSbFPG0t9CXzB5X6gYmluX5uUGCmFSksn_Y1bX0yDy9Rs9C5p8x3FQhnRgMP_PRkVU759zlpsq_IoZ1syhJuIrpBJEADFTiHsnU53eME9O1gfJkAhbKXTbqA5gh6a4JF7zkEc-8zAxmmA_Wc386Kz4S3aOOCc0knFd0mBfIbi7bbniDMBhezhJ4M4BXE8dG2XeE4YMIflnMrcWfj3sL4toWGWouNEjVIMgxWH8rlnznGUWSSvwdJXrSvGd8EXFv-G04Ny1sJKJ5OFeK-wSzm1pUOOkdVUTcUaamjZ-_Ai7r5tBGckdcgh6riJfvBE7MhT8_91Q2aj1t6MV1HHH3ZkAlXKHOzYHJIHyt_98OelR-92KeRwJb4K8QuXSISZHnLwX_8RA2BwauIuwGRR7eZ2cD3-22m73X2CUkulXZnis8NWi7zYh0Q1Qiu27gaJSfH8YcAOi8YfxoZgRjbpGlIouUS4Q82odUdap7OqmDxgk8qBNSlgwW3N_nN1GO8j0uF00exyyF2aUTFmsKZI8jROoG2JyCXC-ghV5ojSeQPRTlliblWcjJtxQw0ipTpxSG_hF9hKK1yJziXL7Hr9HnpuKscpGnerMwaOtyaTQ7QAE_rnJnVKd1-im-yY4s_SG8dF5sA"/><div class="captcha_input"><div class="field_container"><input autocapitalize="off" autocomplete="off" autocorrect="off" class="_5whq input" id="captcha_response" name="captcha_response" type="text"/></div></div></div><input name="lsd" type="hidden" value="AVq_1vee"/><input name="did_submit" type="hidden" value="Search"/><input name="email" type="hidden" value="correct facebook_email"/><input name="_orig_post_vars" type="hidden" value="lsd,did_submit,email"/><input name="captcha_attempt" type="hidden" value="1"/><input class="n o" name="captcha_submit_text" type="submit" value="Wyślij"/><input class="n p" name="captcha_try_text" type="submit" value="Spróbuj inne"/></form></div><div></div></div></div><div class="q"></div></div></div></body></html>

+0

關閉我的頭頂,你說你接受gzip'd的迴應,所以它可能只是壓縮。 – Sinkingpoint

回答

1

由於@Sinkingpoint在他的評論中指出的那樣,你就得到一個壓縮的響應。您可以將其解壓縮(您可以在x.headers['Content-Encoding']中找到編碼),也可以刪除headers中的「接受編碼」。事實上,你不需要「主機」和「接受」(requests自動生成它們),但是你可能需要「用戶代理」。

headers = { 
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64; rv51.0) Gecko/20100101 Firefox/51.0" 
} 
+0

我的新問題,當我使用這個腳本併發送POST請求時,facebook需要驗證碼。但是,當我使用瀏覽器和這個相同的Facebook不需要captcha ...有可能繞過這個? – PythonLearn

+0

顯然是的,但我不願意幫你繞過Facebook的安全機制。 –

+0

我明白,但爲什麼當我使用瀏覽器的Facebook不需要驗證碼? – PythonLearn