簡體   English   中英

為什么發送發布請求在python中不起作用?

[英]Why sending a post request doesn't work in python?

提交表單后,我想從網站解析數據,而我正在使用requests庫來做到這一點。 這是網站 該站點上有一個表格。 提交表單后,頁面將重新加載,並生成一個包含信息的新表,這就是我想要的信息。

手動提交表單時的標題:

activeFormName:report_builder_form
repProviance:66
repStation:40754
parameters:1
start_year:1951
end_year:1963
SearchBtn:جستجو
SearchBtn:جستجو
__sisReportRowCount:10
__sisReportParamType:simple`

我使用數據字典發送請求:

import requests
from bs4 import BeautifulSoup
form_data = {
        'activeFormName':'report_builder_form',
        "repProviance": 66,
        'repStation': 40754,
        'parameters':1 ,
        "start_year": 1951,
        "end_year": 1963,
        "SearchBtn":"%D8%AC%D8%B3%D8%AA%D8%AC%D9%88",
    #     "SearchBtn":"جستجو", ### This line and above are the same.
            "__sisReportParamType": 'simple',
            "__sisReportRowCount": 10
        } 

respones = requests.post(url,data=form_data)
s = BeautifulSoup(respones.content,'lxml')

但是它總是給我一個不包含任何信息的HTML文件。

       import time 
import requests 
from bs4 import BeautifulSoup 
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'} 

url = '.......' 
ses = requests.Session() 
respones = ses.get(url) 
time.sleep(5) 
pay_load = { 
'activeFormName':'report_builder_form', 
"repProviance": 66, 
'repStation': 40754, 
'parameters':1 , 
"start_year": 1951, 
"end_year": 1963, 
"SearchBtn":"%D8%AC%D8%B3%D8%AA%D8%AC%D9%88", 
# "SearchBtn":"جستجو", 
"__sisReportParamType": 'simple', 
"__sisReportRowCount": 10 
} 

s =ses.post(respones.url, data=pay_load) 

soup = BeautifulSoup(s.content,'html.parser') 
print(soup.prettify())

嘗試像這樣發布數據

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM