我知道SO中有许多类似的问题,但是我在{中尝试了get
,post
,data
,params
等的每种组合{1}}包,但我无法提交表单。我要么返回一个空字符串,要么返回同一页面(即:不是按 Submit 之后我希望获得的页面)
requests
该站点最近发生了变化,我记得这些命令之一肯定可以正常工作。为什么现在都不工作?
答案 0 :(得分:2)
您提到过,该网站最近已更改。看来它现在正在使用 form-data 来接收POST请求,并且还需要发送默认值。
总而言之,您的代码应如下所示:
import requests
webserver = 'http://stev.oapd.inaf.it/cgi-bin/cmd'
headers = {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:66.0) Gecko/20100101 Firefox/66.0", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Language": "en-US,en;q=0.5"}
files = {
'submit_form': (None,"Submit"),
'cmd_version': (None,"3.2"),
'track_parse': (None,"parsec_CAF09_v1.2S"),
'track_colibri': (None,"parsec_CAF09_v1.2S_S35"),
'track_postagb': (None,"no"),
"n_inTPC": (None,"10"),
"eta_reimers": (None,"0.2"),
"kind_interp": (None,"1"),
"kind_postagb": (None,"-1"),
"photsys_file": (None,"tab_mag_odfnew/tab_mag_ubvrijhk.dat"),
"photsys_version": (None,"YBC"),
"dust_sourceM": (None,"dpmod60alox40"),
"dust_sourceC": (None,"AMCSIC15"),
"kind_mag": (None,"2"),
"kind_dust": (None,"0"),
"extinction_av": (None,"0.0"),
"extinction_coeff": (None,"constant"),
"extinction_curve": (None,"cardelli"),
"imf_file": (None,"tab_imf/imf_kroupa_orig.dat"),
"isoc_isagelog": (None,"0"),
"isoc_agelow": (None,"1.0e9"),
"isoc_ageupp": (None,"1.0e10"),
"isoc_dage": (None,"0.0"),
"isoc_lagelow": (None,"6.6"),
"isoc_lageupp": (None,"10.13"),
"isoc_dlage": (None,"0.0"),
"isoc_ismetlog": (None,"0"),
"isoc_zlow": (None,"0.0152"),
"isoc_zupp": (None,"0.03"),
"isoc_dz": (None,"0.0"),
"isoc_metlow": (None,"-2"),
"isoc_metupp": (None,"0.3"),
"isoc_dmet": (None,"0.0"),
"output_kind": (None,"0"),
"output_kind": (None,"0"),
"output_evstage": (None,"1"),
"lf_maginf": (None,"-15"),
"lf_magsup": (None,"20"),
"lf_deltamag": (None,"0.5"),
"sim_mtot": (None,"1.0e4"),
".cgifields": (None,"track_parsec"),
".cgifields": (None,"extinction_coeff"),
".cgifields": (None,"dust_sourceC"),
".cgifields": (None,"output_kind"),
".cgifields": (None,"extinction_curve"),
".cgifields": (None,"dust_sourceM"),
".cgifields": (None,"isoc_ismetlog"),
".cgifields": (None,"output_gzip"),
".cgifields": (None,"photsys_version"),
".cgifields": (None,"track_colibri"),
}
r = requests.post(webserver, headers=headers, files = files)
希望这会有所帮助!