我试图得到的网站搜索结果的输出,我用请求后的方法来做它。下面您可以看到表单和从url输入的htmls。我需要在表单的输入中得到每个搜索结果。你知道吗
我尝试了下面的代码,但没有返回任何结果
import requests
from bs4 import BeautifulSoup
# FORM from website
# <form name="form1" method="post" action="payerOrVoenChecker.jsp">
# INPUT from the website
# <input type="text" name="voen" size="38" style="BACKGROUND-COLOR: #ffffff; BORDER-BOTTOM-STYLE: groove;
# BORDER-LEFT-STYLE: groove; BORDER-RIGHT-STYLE: groove; BORDER-TOP-STYLE: groove; COLOR: #000000; FONT-FAMILY:
# Tahoma, Arial; FONT-SIZE: 12px" value="">
request_headers = {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'en-US,en;q=0.9',
'Cache-Control': 'max-age=0',
'Connection': 'keep-alive',
'Content-Type': 'application/x-www-form-urlencoded',
'Host': 'www.e-taxes.gov.az',
'Origin': 'https://www.e-taxes.gov.az',
'Referer': 'https://www.e-taxes.gov.az/ebyn/payerOrVoenChecker.jsp',
'Sec-Fetch-Mode': 'navigate',
'Sec-Fetch-Site': 'same-origin',
'Sec-Fetch-User': '?1',
'Upgrade-Insecure-Requests': '1',
'User-Agent': 'YOUR USER AGENT',
}
voens = {2000460031,
1000877741,
1000877741,
1500403661,
1000877741,
3000489411,
1000877741,
1802142932,
}
tip = ['L',
'P',
]
form_data = {
'tip': tip,
'voenOrName': 'V',
'voen': voens,
'name': '',
'submit': ' Yoxla ',
}
url = 'https://www.e-taxes.gov.az/ebyn/payerOrVoenChecker.jsp'
for voen in voens:
form_data['voen'] = voen
form_data['tip'] = tip
response = requests.post(url, data=form_data, headers=request_headers)
s = BeautifulSoup(response.content, 'lxml')
sContent = s.findAll('table', {'class': 'com'})[0].findAll('tr', recursive=False)[1]
outcome = sContent.get_text().strip()
# .find("tr", recursive=False)
print(outcome)
预期结果将以表格形式出现,我在网站中添加搜索前后的截图,突出显示的是我需要获得的表格
您缺少了
POST
请求主体中要发送的其他项。你知道吗试试这个:
解决这些问题的最佳方法是切换到浏览器中开发人员工具中的“网络”选项卡。Chrome和Firefox的快捷方式都是F12。你知道吗
它将显示浏览器在幕后发送的所有请求的列表。单击与您的URL匹配的一个。你知道吗
右边将打开一个窗格,显示使用了什么方法(GET/POST)、请求中传递了什么头、发送了什么数据(如果是POST)等等
我所做的只是从该选项卡粘贴请求头和表单数据。你知道吗
相关问题 更多 >
编程相关推荐