我正在尝试通过Python中的请求编写一段代码,以填写以下网站(https://linelist.pa.uky.edu/newpage/)中的表格并打印提交的查询显示的信息:
“”” 导入请求
url = "https://linelist.pa.uky.edu/newpage/"
params = {"wavelength_range": "6100-6500", # Specify the wavelength range}
r = requests.post(url, data=params)
print(r.text)
“”“
但问题是,提交查询后,它不会打印网站上显示的结果。
您的目标应用程序没有参数名称
wavelength_range
,而是有一个 wavl
参数和一堆其他参数,并且您使用 POST 方法而不是 /newpage/cgi-bin/qlines.cgi
请求错误的端点
这里是使用POST方法而不是
https://linelist.pa.uky.edu/newpage/cgi-bin/qlines.cgi
从
https://linelist.pa.uky.edu/newpage/
获取数据的示例代码
import requests
from bs4 import BeautifulSoup
url = "https://linelist.pa.uky.edu/newpage/cgi-bin/qlines.cgi"
params = "wavl=6100-6500&wave=Angstrom&air=Vacuum&radv=&rvtp=vrad&wacc=&elmion=&akival=&akitype=Aki&akizero=incl&abun=&depl=&elo=&ener=cm%5E-1&ehi=&nmax=&type=All&auto=Show&form=spec&form=type&form=term&form=angm&jval=usej&tptype=as_a&form=ener&mode=HTML+&mlin=10000" # Specify the wavelength range}
r = requests.post(url, data=params).text
soup = BeautifulSoup(r, 'lxml')
for i in soup.findAll('a', href=True):
print(f"{i.text.strip()}: {i['href']}")
2D-4Po: qmult.cgi?10?3?15027?15045?SpTtTrAmLvMjPa?0
3Fo-3G: qmult.cgi?14?10?22429?22444?SpTtTrAmLvMjPa?0
3G-(5/2,3/2)o: qmult.cgi?31?3?58494?58533?SpTtTrAmLvMjPa?0
ASD: https://physics.nist.gov/cgi-bin/ASBib1/Elevbib/make_query.cgi?spectra=Ga%20IV&method=EL&order=1
(5/2,1/2)-1Fo: qmult.cgi?31?3?58582?58599?SpTtTrAmLvMjPa?0
ASD: https://physics.nist.gov/cgi-bin/ASBib1/Elevbib/make_query.cgi?spectra=Ga%20IV&method=EL&order=1
f6D-6Po: qmult.cgi?25?0?40739?41200?SpTtTrAmLvMjPa?0
ASD: https://physics.nist.gov/cgi-bin/ASBib1/Elevbib/make_query.cgi?spectra=Mn%20I&method=EL&order=1
f6D-6Po: qmult.cgi?25?0?40739?41201?SpTtTrAmLvMjPa?0
ASD: https://physics.nist.gov/cgi-bin/ASBib1/Elevbib/make_query.cgi?spectra=Mn%20I&method=EL&order=1
4Do-4D: qmult.cgi?9?0?12135?12187?SpTtTrAmLvMjPa?0
请告诉我这是否适合您!