问题
*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.
cURL Script
$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
- 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>
Notice the onChange
event which triggers the reloaded page with the next dropdwon
and its' respective options
.
What I'm trying to accomplish
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.
So my database looks like this:
option_1 | option_2 | option_3 | price |
field_1 | field_2 | field_3 | 25 |
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--
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)
Edit 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.
回答1:
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 !!!
来源:https://stackoverflow.com/questions/12925442/how-to-use-curl-to-post-form-values-on-form-using-js