I want to achieve is every time according to the keyword search Baidu results page, such as Baidu search results are such, Baidu promotion content Ka Zhongwen:
And I use curl to crawl the result is this:
That is to say that each crawl results are unable to crawl to the content of Baidu promotion. Ask which Master can guide, I just get started, hope you are not hesitate to guide. I thanked him first.
Where the PHP fetch code is as follows:
Reply to discussion (solution)
The promotion of the content is the page load and then call JS two requests to obtain, write to the page. So with curl you can only get to HTML something.
And JS loaded, you need to use curl to get it js gets the URL to get.
The promotion of the content is the page load and then call JS two requests to obtain, write to the page. So with curl you can only get to HTML something.
And JS loaded, you need to use curl to get it js gets the URL to get.
But this Baidu promotion content by viewing the page source code is can see? Will the information generated by invoking JS appear in the Web page source code?
Your user-agent is not well simulated, so you can't.
In fact, there is no need to use post, directly with get can be.
Modify the following:
$url = "http://www.baidu.com/s?wd= life force"; $header = Array ( ' user-agent:mozilla/5.0 (Windows NT 5.1) applewebkit/ 537.36 (khtml, like Gecko) chrome/33.0.1750.146 safari/537.36 '); $ch = Curl_init (); curl_setopt ($ch, Curlopt_url, $url); curl_setopt ($ch, Curlopt_httpheader, $header); curl_setopt ($ch, Curlopt_returntransfer, 1);//Execute $content = curl_exec ($ch), if ($content = = FALSE) { echo "error:". Curl_error ($ch);} Close Curl_close ($ch); The result of the output echo $content;
Your user-agent is not well simulated, so you can't.
In fact, there is no need to use post, directly with get can be.
Modify the following:
$url = "http://www.baidu.com/s?wd= life force"; $header = Array ( ' user-agent:mozilla/5.0 (Windows NT 5.1) applewebkit/ 537.36 (khtml, like Gecko) chrome/33.0.1750.146 safari/537.36 '); $ch = Curl_init (); curl_setopt ($ch, Curlopt_url, $url); curl_setopt ($ch, Curlopt_httpheader, $header); curl_setopt ($ch, Curlopt_returntransfer, 1);//Execute $content = curl_exec ($ch), if ($content = = FALSE) { echo "error:". Curl_error ($ch);} Close Curl_close ($ch); The result of the output echo $content;
Thank you for your reply. Your conclusion is correct. I also have a problem here, that is, the crawl of the page image can be displayed the first time, after the display is not.
View source code to find the picture address is the real address ah, but it is not shown, what ideas can bypass this anti-chain. It seems impossible to forge a route in curl.
This you need to look at the page has no hidden parameters, usually those will affect.
For example, JS will also. And this is another problem, we should open a new post discussion.