Writing a web crawler in Python (vi): A simple Baidu paste small crawler

Source: Internet
Author: User
Tags in python
#-*-Coding:utf-8-*-#---------------------------------------# program: Baidu paste Crawler # version: 0.1 # Author: Why # Date: 201  
3-05-14 # language: Python 2.7 # Operation: Enter the address with the paging, remove the back of the 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_pa  
        Ge,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.urlop  
      
En (url + str (i)). Read () F.write (M) f.close () #--------Enter 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 the post, remove the number after 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 page: \ n ')] #--------ENTER hereParameter------------------#调用 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.