Python Urllib POST 响应未获取正确的值
Python Urllib POST response is not fetching correct values
为了学习 POST parmaeter urllib,我试图在参数中输入的以下代码中获取特定日期的 table 值。但是,它没有 return 9 月 12 日的值,而是响应显示日期是 10 月 12 日。
使用 POSTMAN,响应是针对正确日期 return 编辑的,但是对于 Python,我无法获得当前月份以外的值。对可能导致这种情况的原因有任何解释吗?任何 help/suggestion 表示赞赏。
import urllib
import urllib2
url = ''
data = urllib.urlencode({'priceDate.month' : '09', 'priceDate.date' : '12','priceDate.year':'2016','submit':'Show Prices'})
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
d = response.read()
print d
只需使用 requests
模块。
import requests as re
url = "https://www.treasurydirect.gov/GA-FI/FedInvest/selectSecurityPriceDate.htm"
parms = {'priceDate.month':'09','priceDate.day':'12','priceDate.year':'2016','submit':'CSV+Format'}
resp = re.post(url, parms)
resp.content
为了学习 POST parmaeter urllib,我试图在参数中输入的以下代码中获取特定日期的 table 值。但是,它没有 return 9 月 12 日的值,而是响应显示日期是 10 月 12 日。
使用 POSTMAN,响应是针对正确日期 return 编辑的,但是对于 Python,我无法获得当前月份以外的值。对可能导致这种情况的原因有任何解释吗?任何 help/suggestion 表示赞赏。
import urllib
import urllib2
url = ''
data = urllib.urlencode({'priceDate.month' : '09', 'priceDate.date' : '12','priceDate.year':'2016','submit':'Show Prices'})
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
d = response.read()
print d
只需使用 requests
模块。
import requests as re
url = "https://www.treasurydirect.gov/GA-FI/FedInvest/selectSecurityPriceDate.htm"
parms = {'priceDate.month':'09','priceDate.day':'12','priceDate.year':'2016','submit':'CSV+Format'}
resp = re.post(url, parms)
resp.content