python - 搜索每个值时,发送 POST 请求时输出为空列表
问题描述
我曾经在网络中找到form_data 列表,然后发送 POST 请求,但在这种情况下,没有这样的事情,而不是我接受请求有效负载。因此,该方法似乎行不通。
这是该网站的网址: https ://www.e-taxes.gov.az/ebyn/vergiBorcu.html
输入: <input ng-model="" voen="" placeholder="1234567891" type="text" class="form-control ng-valid ng-dirty ng-valid-parse ng-touched ng-empty" id="voen">
这是我尝试过的代码:
import requests
from bs4 import BeautifulSoup
import csv
import json
request_headers = {
'Accept': 'application/json, text/plain, */*',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'en,en-GB;q=0.9',
'Connection': 'keep-alive',
'Content-Length': '50',
'Content-Type': 'application/json;charset=UTF-8',
'Cookie': 'ETAXES=etaxes; JSESSIONID=C033E796031CA5C84A3A7B38E24330D4',
'Host': 'www.e-taxes.gov.az',
'Origin': 'https://www.e-taxes.gov.az',
'Referer': 'https://www.e-taxes.gov.az/ebyn/vergiBorcu.html',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/75.0.3770.142 Safari/537.36',
}
taxid = {
'8400260181',
'1700393071',
'1004199751',
'2002283071',
}
payloads = {"METHOD": "wsEbynGetDebetSum",
"voen": taxid,
}
url = 'https://www.e-taxes.gov.az/ebyn/vergiBorcu.html'
for voen in taxid:
payloads['voen'] = voen
response = requests.post(url, data=json.dumps(payloads), headers=request_headers)
s = BeautifulSoup(response.content, 'lxml')
sContent = s.find('div', class_="col-sm-3").find_all("input", class_="form-control ng-pristine")
print(voen)
print(sContent)
with open('taxDebt.csv', 'w', newline='', encoding='utf-8') as myfile:
writer = csv.writer(myfile, quoting=csv.QUOTE_ALL, delimiter="\n")
writer.writerow(sContent)
我希望得到类似的输出,Debt: "value"
但它返回空列表:
1700393071
[]
1004199751
[]
8400260181
[]
2002283071
[]
解决方案
我相信您的find
语法不正确。您正在寻找一个看起来像的标签,<div class="col-sm-3">
为了使用 BeautifulSoup 获得它,试试这个
s.find("div", class_="col-sm-3")
find_all
调用也必须修改:
sContent = s.find('div', class_= "col-sm-3").find_all("input", class_= "form-control ng-pristine")
推荐阅读
- node.js - 猫鼬(检查并保存如果新)
- java - 如何知道 JVM 因 Segfault 而崩溃的原因?
- asp.net-mvc - '值不能为空。参数名称:ViewStart.cshtml 上的 virtualPath'
- c# - Win2D API 随机失败,并出现错误“必须从同一工厂实例创建一起使用的对象”。
- android - 在 Android 屏幕录制中 - 如何获取每一帧?
- c# - 如何停止项目模板概念中的向导操作(IWizard)
- excel - 如何在同一类别下仅识别一个最小的数字
- powershell - 在powershell中将system.array对象转换为json对象
- python - 如何从 argparse 解析器对象中查询我期望的参数类型?
- wordpress - 使用 wpml 插件联系表格 7 占位符文本翻译