我正在使用下面的代码从网站上抓取数据,其中三个字段由用户输入填充。
import requests
import json
URL = "http://example.com"
docs = input("Doc type: ")
fromdate = input("From: ")
todate = input("To: ")
r = requests.post(url = URL, json = {"MaxRows":0,"RowsPerPage":0,"StartRow":0,"DocTypes":'"{}"',"FromDate":'"{}"',"ToDate":'"{}"'.format(docs,fromdate,todate)})
r.json()
但我收到这样的错误
{'exceptionMessage':'输入字符串格式不正确。','exceptionType':'System.FormatException','message':'发生错误。','stackTrace':'在System.Number.StringToNumber (String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)\r\n 在 System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)\r\n 在 BrowserView.Models.SearchCriteria.Parse() \r\n 在 BrowserView.Controllers.SearchController.SearchTwo(SearchCriteria 条件)'}
我想要下面给出的代码
json = {"MaxRows":0,"RowsPerPage":0,"StartRow":0,"DocTypes":'"{}"',"FromDate":'"{}"',"ToDate":'"{}"'.format(docs,fromdate,todate)}
当用户输入数据时是这样的
json = {"MaxRows":0,"RowsPerPage":0,"StartRow":0,"DocTypes":"TAX","FromDate":"20201104","ToDate":"20201218"}