Here will not give you nonsense, directly on the code, the Code of interpretation are in the comments, do not understand also don't ask me, learn basic knowledge to go!
The code is as follows:
#-*-Coding:utf-8-*-
#---------------------------------------
# program: Baidu Paste Stick Crawler
# Version: 0.1
# Author: why
# Date: 2013-05-14
# language: Python 2.7
# Action: Enter the address with paging, remove the last number, set the start and end pages.
# function: Download all pages in the corresponding page number and save as HTML file.
#---------------------------------------
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 section ' + str (i) + ' page and store 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 Baidu Bar in Shandong University
#bdurl = ' http://tieba.baidu.com/p/2296017831?pn= '
#iPostBegin = 1
#iPostEnd = 10
Bdurl = str (raw_input (U ' Please enter the address of the bar, remove the number behind the pn=: \ n '))
begin_page = Int (raw_input (U ' Please enter the number of pages to start: \ n '))
end_page = Int (raw_input (U ' Please enter end of page: \ n '))
#--------Enter the parameters here------------------
#调用
Baidu_tieba (Bdurl,begin_page,end_page)
The above is a Python crawl Baidu post a simple code, very practical bar, you can expand their own.