Php's Baidu keyword ranking query function, the second page of the site does not return the value of the first page of keywords are returned normal results, the second page does not receive the value, do not know what is going on, the code is as follows
2) {return array (, 0);} try {$ contents = file_get_contents ("http://www.baidu.com/s? Wd = $ enKeyword & pn = $ firstRow ");} catch (Exception $ e) {echo 'timeout'; die ();} 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, $ page, ++ $ k); // print_r ($ arr_rank); return array ($ px, $ page, ++ $ k ); // $ px ranking, where $ page is the page number, and ++ $ k is the location of the page number where the keyword is located} unset ($ contents); if ($ rsState = false) {search ($ keyword, $ url, ++ $ page) ;}}?>
'; $ Arr_paiming2 = search ($ keyword2, $ site2); print_r ($ arr_paiming2); echo'
'; $ Arr_paiming3 = search ($ keyword3, $ site3); print_r ($ arr_paiming3); echo'
';?>
Reply to discussion (solution)
Is this problem complicated?
I do not know the meaning of the returned data
I don't know what the second page is.
You have no operations on the second page.
I do not know the meaning of the returned data
I don't know what the second page is.
You have no operations on the second page.
You can see here, http://hi.baidu.com/alexkh/item/023a90dd18ca59c51a72b415
I just proposed this function.
// Print_r ($ arr_rank); return array ($ px, $ page, ++ $ k); // $ px ranking, $ page is the page number, + $ k indicates the specific location of the number of pages where the keyword is located.
In fact, it is strange that in this place, there are values in print_r (), and the return value is empty.
Let's show you what to expect.
If 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 );
}
Should the result be like this? (Input parameters are printed at the search entry)
Baidu optimization, ppc.admin5.com, 1
Array
(
[0] => 6
[1] => 1
[2] => 7
)
Hotel booking in Qingdao, www.20.0512.com, 1
Hotel booking in Qingdao, www.20.0512.com, 2
Array
(
[0] => 4
[1] => 2
[2] => 5
)
Qingdao hotel reservation, www.17u.com, 1
Array
(
[0] => 2
[1] => 1
[2] => 3
)
Thanks. it seems that I still don't understand algorithms.
If 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 );
}
Should the result be like this? (Input parameters are printed at the search entry)
Baidu optimization, ppc.admin5.com, 1
Array
(
[0] => 6
[1] => 1
[2] => 7
)
Hotel booking in Qingdao, www.20.0512.com, 1
Hotel booking in Qingdao, www.20.0512.com, 2
Array
(
[0] => 4
[1] => 2
[2] => 5
)
Qingdao hotel reservation, www.17u.com, 1
Array
(
[0] => 2
[1] => 1
[2] => 3
)