tazeha Posted September 11, 2014 Share Posted September 11, 2014 I write following code to get Multiple page of the this site: www.mobile.ir This website have mobile price category .. this category have 42 navigation page. I write following code with curl_multi_init and xpath to get data from Multiple page from category. $ch1= curl_init ("http://www.mobile.ir/phones/prices.aspx");$ch2 = curl_init ("http://www.mobile.ir/phones/prices.aspx?sort=date&dir=desc&brandid=0&terms=&duration=14&pagesize=50&price_from=-1&price_to=-1&provinceid=0&shopid=0&page=2");curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);curl_setopt($ch1,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');curl_setopt($ch1, CURLOPT_HEADER, 0);curl_setopt($ch1, CURLOPT_ENCODING, 'UTF-8');curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);curl_setopt($ch2,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');curl_setopt($ch2, CURLOPT_HEADER, 0);curl_setopt($ch2, CURLOPT_ENCODING, 'UTF-8');$mh = curl_multi_init();//add the two handlescurl_multi_add_handle($mh,$ch1);curl_multi_add_handle($mh,$ch2);$active = null;//execute the handlesdo {$mrc = curl_multi_exec($mh, $active);} while ($mrc == CURLM_CALL_MULTI_PERFORM);while ($active && $mrc == CURLM_OK) {if (curl_multi_select($mh) != -1) {do {$mrc = curl_multi_exec($mh, $active);} while ($mrc == CURLM_CALL_MULTI_PERFORM);}}$dom = new DOMDocument('1.0', 'utf-8');libxml_use_internal_errors(true);$dom->loadHTML($mrc);libxml_clear_errors();$xpath = new DOMXpath($dom);$data = array();$table_rows = $xpath->query('//table[@id="price_table"]/tbody/tr'); // target the row (the browser rendered <tbody>, but actually it really doesnt have one)if($table_rows->length <= 0) { // exit if not foundecho 'no table rows found';exit;}$s = "stxECna";foreach($table_rows as $tr) { // foreach row$row = $tr->childNodes;if($row->item(0)->tagName != '<tr class="carHeader"> <td>نام کارخانه </td> <td>نام خودرو </td> <td>قیمت نمایندگی (ریال) </td> <td>قیمت بازار (ریال) </td> </tr>') { // avoid headers$data[] = array('Name' => trim($row->item(2)->nodeValue),'Price' => trim($row->item(4)->nodeValue),);}}echo '<pre>';print_r($data); But don't display data ... when I use curl_init() to get data from one page without problem working and displaying data (name and price) but when use curl_multi_init dont display I really need.. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 11, 2014 Share Posted September 11, 2014 You're trying to treat the return value of curl_multi_exec as HTML, apparently. That function returns an integer constant telling you the status of the various requests. You need to use curl_multi_getcontent to get the contents from the individual requests. The contents of all requests are not all lumped together into a single response string, they are still separate. 1 Link to comment Share on other sites More sharing options...
tazeha Posted September 11, 2014 Author Share Posted September 11, 2014 You're trying to treat the return value of curl_multi_exec as HTML, apparently. That function returns an integer constant telling you the status of the various requests. You need to use curl_multi_getcontent to get the contents from the individual requests. The contents of all requests are not all lumped together into a single response string, they are still separate. Thanks. Can you write fix code with multi_get_content? Link to comment Share on other sites More sharing options...
justsomeguy Posted September 11, 2014 Share Posted September 11, 2014 No, I am not going to write your code for you. You ask that a lot. You need to show some effort. 1 Link to comment Share on other sites More sharing options...
tazeha Posted September 12, 2014 Author Share Posted September 12, 2014 No, I am not going to write your code for you. You ask that a lot. You need to show some effort. But I'm very trying to work with this in the More sites witch write about curl Link to comment Share on other sites More sharing options...
justsomeguy Posted September 12, 2014 Share Posted September 12, 2014 Did you look up the manual page for curl_multi_getcontent? Are you trying anything new with your code? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now