【发布时间】:2020-12-31 20:23:24
【问题描述】:
我正在使用下面的代码从网站上抓取数据,其中三个字段由用户输入填充。
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 样式、NumberFormatInfo 信息)\r\n at BrowserView.Models.SearchCriteria.Parse()\r\n at 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"}
【问题讨论】:
标签: python python-requests python-jsons python-requests-json