Here will not give everyone nonsense, directly on the code, the interpretation of the code in the comments inside, do not understand do not ask me to learn the basics to go!
Copy Code code as follows:
#-*-Coding:utf-8-*-
#---------------------------------------
# program: Baidu Paste the crawler
# Version: 0.1
# Author: why
# Date: 2013-05-14
# language: Python 2.7
# operation: Enter the address with the paging, remove the back number, set the starting page and end page.
# function: Download all pages in the corresponding page number and store them as HTML files.
#---------------------------------------
Import String, Urllib2
#定义百度函数
def Baidu_tieba (url,begin_page,end_page):
For I in range (Begin_page, end_page+1):
sname = String.zfill (i,5) + '. html ' #自动填充成六位的文件名
print ' is downloading the ' + str (i) + ' page and storing it as ' + sname + ' ... '
f = open (sname, ' w+ ')
m = urllib2.urlopen (url + str (i)). Read ()
F.write (M)
F.close ()
#--------Enter the parameters here------------------
# This is the address of a post in the Baidu bar of Shandong University
#bdurl = ' http://tieba.baidu.com/p/2296017831?pn= '
#iPostBegin = 1
#iPostEnd = 10
Bdurl = str (raw_input (U ' Please enter the address of post, remove the number after pn=: \ n '))
begin_page = Int (raw_input (U ' enter start page: \ n '))
end_page = Int (raw_input (U ' Please enter end page: \ n '))
#--------Enter the parameters here------------------
#调用
Baidu_tieba (Bdurl,begin_page,end_page)
The above is Python crawl Baidu bar a piece of simple code, very practical, you can expand their own.