PHP Baidu keyword ranking query function, the second page of the site no return value

Source: Internet
Author: User
The first page of the keywords are returned to normal results, the second page does not receive the value, do not know how, the code is as follows
 2) {return array (0,0,0);} try{$contents = file_get_contents ("http://www.baidu.com/s?wd= $enKeyword &pn= $firstRow");} catch (Exception $e) {echo ' timeout ';d ie ();} Preg_match_all ('/
 
  
   ]*?class= "Result" [^>]*>[\s\s]*?<\/table>/i ', $contents, $rs), foreach ($rs [0] as $k = $v) {$px + +; $v = str _replace (Array (" 
   ,"), "", $v),//Remove the Bold label if (Strstr ($v, $url) of the English keyword) {$rsState = true; $arr _rank=array ($px, $pag e,++ $k);//print_r ($arr _rank); return Array ($px, $page, + + $k),//$px rank, $page is the number of pages, + + $k is the exact location of the page number where the keyword is located}}unset ($contents if ($rsState = = = False) {search ($keyword, $url, + + $page);}}? > 
    '; $arr _paiming2=search ($keyword 2, $site 2);p Rint_r ($arr _paiming2); Echo '
   
'; $arr _paiming3=search ($keyword 3, $site 3);p Rint_r ($arr _paiming3); Echo '
';? >


Reply to discussion (solution)

Is this a complicated question?

Do not know what the return data means
I don't know what the second page is.

You don't have an example. Action on the second page

Do not know what the return data means
I don't know what the second page is.

You don't have an example. Action on the second page

You can see here, http://hi.baidu.com/alexkh/item/023a90dd18ca59c51a72b415.
I just put this function forward.

Print_r ($arr _rank);             


In fact, Strange is strange in this place, Print_r () when there is value, return time is empty

Let's get a sensible look at it.

You have recursion, why not return recursive data?
if ($rsState = = = False)
{
Search ($keyword, $url, + + $page);
}
At least because
if ($rsState = = = False)
{
Return search ($keyword, $url, + + $page);
}

The result should be like this? (Incoming parameters are printed in search entry)
Baidu optimization, ppc.admin5.com, 1
Array
(
[0] = 6
[1] = 1
[2] + 7
)
Qingdao Hotels, www.hotel0512.com, 1
Qingdao hotels, www.hotel0512.com, 2
Array
(
[0] + 4
[1] = 2
[2] = 5
)
Qingdao Hotels, www.17u.com, 1
Array
(
[0] = 2
[1] = 1
[2] + 3 br>)

Thank you, I guess I still don't know the algorithm.

If you have recursion, why not return the recursive data?
if ($rsState = = = False)
{
Search ($keyword, $url, + + $page);
}
At least because it should be
if ($rsState = = = False)
{
Return Search ($keyword, $url, + + $page);
}

Should the result be like this? (Incoming parameters are printed at search entrance)
Baidu optimization, ppc.admin5.com, 1
Array
(
[0] = 6
[1] = 1
[2] = 7
)
Qingdao Hotel Reservation, www.hotel0512.com, 1
Qingdao Hotel Reservation, www.hotel0512.com, 2
Array
(
[0] = 4
[1] = 2
[2] = 5
)
Qingdao Hotel Reservation, www.17u.com, 1
Array
(
[0] = 2
[1] = 1
[2] = 3
)

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.