如何使用cURL在表单上使用JS来POST形式值 [英] How to use cURL to POST form values on form using JS
问题描述
* 很长的帖子对不起* *
我在PHP中使用cURL post
post
的结果需要一些帮助,因为表单有点不寻常。
*Sorry for the long post *
I'm using cURL in PHP to post
some form fields in effort to return the result of the post
Need some help as the form is somewhat unusual.
$ch = curl_init();
$data = array('field_1_name' => 'field_value',
'field_2_name' => 'field_value',
'field_3_name' => 'field_value',
);
curl_setopt($ch, CURLOPT_URL,'http://url.com');
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$fp = fopen('data.php', 'w');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_exec ($ch);
curl_close ($ch);
fclose($fp);
您应该注意的事情
Things you should be aware of
- 字段不是
text-fields
,而是收音机
和dropdown
字段。 - 表单包含
JS
,但firebug控制台不显示AJAX
posts - 改为使用SESSIONS
和HTTP-CACHE
。 - 选择表单字段后,页面似乎
reload
,并插入下一个下拉列表的值。 (再次,firebug不会将此显示为AJAX
请求。)
- The fields are not
text-fields
but rather a combination ofradio
anddropdown
fields. - The form contains
JS
but firebug console is not showingAJAX
posts - instead the form works withSESSIONS
andHTTP-CACHE
data. - Once a form field is selected, the page seems to
reload
and the values of the next dropdown are inserted. (Again firebug is not showing this as anAJAX
request.)
表单上的下拉菜单
字段示例
Here's an example of a dropdown
field on the form
<select name="field_name" onchange="document.getElementById('uploadForm').action.value='RELOAD';document.getElementById('uploadForm').reloadTrigger.value='trigSize';document.getElementById('uploadForm').submit();">
<option value="option_1">option_1</option>
<option value="option_2">option_2</option>
<option value="option_3">option_3</option>
</select>
请注意触发重载的 onChange
页面,其中包含下一个 dropdwon
及其各自的选项
。
Notice the onChange
event which triggers the reloaded page with the next dropdwon
and its' respective options
.
每个下拉菜单
字段包含各种选项。根据在表单上选择的组合,最终网页重新加载会根据选择的这些选项返回价格。我需要将价格和所选选项保存到我的数据库。
Each dropdown
field contains various options. Based on the combination selected on the form, the final page reload returns a price based on these options selected. I need to save the price and the options selected to my database.
option_1 | option_2 | option_3 | price |
field_1 | field_2 | field_3 | 25 |
我包含所有这些信息,因为有体验的人可能指向我在一个更好的方向(意思:toots / libraries / tutorials等)。我不知道 cURL
是否适合这项工作。我喜欢使用 PHP
。那么你们怎么想?感谢您的时间和建议。
I'm including all this information because someone with experience can possibly point me in a better direction (meaning: toots/libraries/tutorials/etc.) I'm not sure if cURL
is right for this job. I prefer to work with PHP
. So what do you guys think? Thank you for your time and suggestions. I welcome and appreciate all helpful information.
- Side Note -
我在 RUBY中写了一个脚本
使用 WATIR-WebDriver
是成功地刮取信息,但是工作方式太慢。每个产品平均有5,000种不同的组合,这种方法每分钟只返回约10次。 (FAIL)
--Side Note--
I wrote a script in RUBY
using WATIR-WebDriver
that is successfully scraping the information, but is working way too slow. Each product has on average of 5,000 different combinations and this method was only returning about 10 per minute. (FAIL)
编辑1
此表单不在我的服务器上,并且不是由我拥有或操作。我打算刮掉表单返回的数据。
Just to clarify. This form is not on my server and is not owned or operated by me. I'm intending to scrape the data returned by the form.
推荐答案
看起来你想得到最终重载的结果将返回HTML表单中的价格。最后一页将具有所有选择的值和价格。现在你不需要抓住除价格之外的其他值,因为你将它们传递给窗体。价格可以通过正则表达式获取。这些值可以轻松地保存在数据库中。
It seems that you want to get result of final reload that would return the price in HTML Form. The final page will have all the values selected and the price. Now you need not to grab other values except price as you passed them to the form. The price can be grabbed through regular expression.These values can easily be saved in your database.
我认为这是可能的解决方案!
I think this would be possible solution !!!
这篇关于如何使用cURL在表单上使用JS来POST形式值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!