Ruby / Python中的POST请求返回'无数据'

时间:2016-04-02 16:22:23

标签: python ruby post web-scraping python-requests

我试图通过Ruby或Python为以下网站上的表单发出POST请求: http://diamond-cut.com.au/holloway_cut_adviser.htm

请求返回“无数据”。'我想我从我的请求标题中省略了某些内容(例如,用户代理,接受。包括这些参数并没有改变结果)

返回的最小代码'无数据'在Ruby中:

require 'restclient'
url='http://www.pricescope.com/hca.php'
params = {"depth_textbox" => '60',
          "table_textbox" => '57',
          "crown_listbox" => "0",
          "crown_textbox" => '34',
          "pavilion_listbox" => "0",
          "pavilion_textbox" => '40.5',
          "cutlet_textbox" => "0"}

page=RestClient.post(url,params)

在Python中:

import requests
url='http://www.pricescope.com/hca.php'
params = {"depth_textbox" : '60',
          "table_textbox" : '57',
          "crown_listbox" : "0",
          "crown_textbox" : '34',
          "pavilion_listbox" : "0",
          "pavilion_textbox" : '40.5',
          "cutlet_textbox" : "0"}
r=requests.post(url,params)

2 个答案:

答案 0 :(得分:2)

您需要稍微使用标题:

headers = {'Referer': 'http://www.pricescope.com/hca.php'}

r = requests.post(url, data=params, headers=headers)
print r.content

答案 1 :(得分:-1)

在你的python代码中,它应如下所示。

  

R = requests.post(URL,数据=参数)

这个links也可以帮助您理解POST语法。