Some time ago, in order to find the keyword ranking of Lao Wang python, I wrote a keyword ranking for searching web pages using python.Program, It seems that the effect is not bad. In particular, it is very convenient to search for webpages with the keyword ranking back. You don't have to manually flip pages one by one.Code.
#! /Usr/bin/ENV Python
#-*-Coding: UTF-8 -*-
# @ Author: WL
# @ Qq: 280026798@qq.com
# @ Description: Check the ranking of a given keyword on Baidu
Import sys
Import urllib, urllib2
Import re
DefBaidu (W, PN ):
'''Return the content of the current page '''
Url ="Http://www.baidu.com/s? "
Values = {
"W": W. encode ('Gbk','Ignore'),
"PN": PN
}
Data = urllib. urlencode (values)
Newurl = URL + Data
Response = urllib2.urlopen (newurl)
The_page = response. Read ()
ReturnThe_page
Def Ana (data, mysite, PN ):
'''Location of the detection keyword '''
O = Re. Compile ( R 'href = "(. + ?) "' )
F = O. findall (data)
Line = Pn
For FF In F:
FF = ff. Strip ()
If Not Re. Search ( "^ S \? " , Ff) And Re. Search ( "^ Http :\/\/" , Ff) And Not Re. Search ( 'Baidu. com' , Ff ):
If Re. Search (mysite, ff ):
Print "*" , Line, FF
Return True
Else :
Print Line, FF
Line = line + 1
Continue
If _ Name _ = "_ Main __" :
Mysite = SYS. argv [ 2 ]
Pn = 1
While True:
Keyword = SYS. argv [ 1 ]. Decode ( 'Gbk' )
Data = Baidu (keyword, PN)
Checkflag = ANA (data, mysite, PN)
If Not Checkflag:
Pn = pN + 10
Print "Page % S " % STR (INT (PN )/ 10 )
Else :
Print 'Found: % S ' % (Mysite)
Break
Else :
Print 'Not found: % S ' % (Mysite) usage: first save it as a python file, and then run it, follow the steps below. The Python XXX. py keyword URL can be used to locate the keyword in the baidu search list.
ArticleLink: http://www.cnpythoner.com/post/webkeyword.html reprint please keep, thank you!