前阵子刚开始试着用python捞公开数据库的资料
程式码如下
import requests
from bs4 import BeautifulSoup as soup
payload={
"accountingyear":"",
"item":"00",
"crop":"001",
"city":"00",
"btnSend":"(unable to decode value)"
}
accountingyear=["100","101"]
for y in accountingyear:
payload['accountingyear']=y
print(payload)
r=requests.post("http://agr.afa.gov.tw/afa/pgcropcity.jsp",data=payload)
print(r)
soup=soup(r.text.encode('utf-8'),'html.parser')
print(soup)
原本预期会得到100年, 101年的资料
可是结果是
{'accountingyear': '100', 'item': '00', 'crop': '001', 'city': '00',
'btnSend': '(unable to decode value)'}
<Response [200]>
<html><head>......</html>
{'accountingyear': '101', 'item': '00', 'crop': '001', 'city': '00',
'btnSend': '(unable to decode value)'}
<Response [200]>
[]
结果变成只有得到100年的资料,101年的资料只有[]
想知道是要如何解决
谢谢