Это работает для меня.Установите энергию - умножьте на 10 в полезной нагрузке.Запросите конечную точку, извлеките соответствующие фрагменты и сохраните в файле.
Довольно просто.Надеюсь, что это решит вашу проблему.
import requests
from bs4 import BeautifulSoup
# set the energy - you proposed a value of 2
energy = 2
# set the right payload - multiply the energymax by 10 - you wanted this
payload = {
"ZNum": 31,
"OutOpt": "PIC",
"Graph6": "on",
"NumAdd": 1,
"Output": "on",
"WindowXmin": energy,
"WindowXmax": energy*10,
"ResizeFlag": "on"
}
# define path to store data
path_to_output_file = "C:/myfile.txt"
# define the correct endpoint
url = "https://physics.nist.gov/cgi-bin/Xcom/xcom3_1"
# make the request to the endpoint
r = requests.post(url, data=payload)
# load the response into BeautifulSoup
soup = BeautifulSoup(r.text, "html.parser")
# identify the rows that hold your data (they share same bgcolor)
trs = soup.find_all('tr', attrs={'bgcolor': '#FFFFCC'})
# open a file to store the data
with open(path_to_output_file, 'w', encoding='utf-8') as f:
# loop through the rows and extract the values
for tr in trs:
tds = tr.find_all('td')
# list comprehension that finds and then joins the values of all columns by a semicolon
# the first td is blank and therefor omitted
data_line = ";".join([td.get_text() for td in tds[1:]])
# write the data to the file
f.write("{}\n".format(data_line))