[Python] web crawler (vi): A simple Baidu paste small reptile __python

Source: Internet
Author: User

http://blog.csdn.net/pleasecallmewhy/article/details/8927832

[Python] View plain Copy # -*- coding: utf-8 -*-   #---------------------------------------    #    Program: Baidu paste crawler    #    version:0.1   #    Author:why   #    date:2013-05-14   #    language:python 2.7    #    Operation: Enter the address with pagination, remove the number of the back, 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  ' downloading the first '  + sTR (i)  +  ' Web page, and store it as '  + sName +  ' ... '             f = open (sname, ' w+ ')             m = urllib2.urlopen (Url + str (i)). Read ()             f.write (m)            f.close ()            #--------  Here input parameters  ------------------      #   This is the Shandong University of Baidu posted in a post address    #bdurl  =  ' http://tieba.baidu.com/p/2296017831?pn= '     #iPostBegin  = 1   #iPostEnd  = 10      bdurl =  STR (raw_input (U ' Please enter the address of the post bar, remove the number after pn=: \ n '))    begin_page = int (raw_input (U ' enter start page: \ n '))    End_page = int (raw_input (U ' Please enter the end page: \ n '))    #--------  Here enter parameter  ------- -----------          #调用    Baidu_tieba (bdurl,begin_page,end_page)  

Related Article

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.