Python Learning simple web crawler

Source: Internet
Author: User

0x00 case Crawl All pictures of a page in the blog park and download to local

A continuous week of Python, harvest a lot, mainly to exercise their temper ... Don't say a word, put on the script first

#Coding:utf-8ImportUrllib2ImportReurl="https://www.cnblogs.com/peterpan0707007/p/7620048.html"Headers={'user-agent':'mozilla/5.0 (Windows NT 10.0; WOW64; rv:59.0) gecko/20100101 firefox/59.0'}req=urllib2. Request (url,headers=headers) Resp=Urllib2.urlopen (req). Read ()Data=re.compile (R ' Http:.+\.png '). FindAll (resp) #正则匹配png图片#Print Data forIinchData:with Open ('Result.txt','a') as Fw:fw.write (i+'\ n') with open ('Result.txt','R') as fr: forLineinchfr.readlines (): Response=Urllib2.urlopen (line). read () filename=line.strip ('\ n'). Split ('-') [2]+'. PNG'with open (filename,'WB') as Fw:fw.write (response)Print ' Done'

Run results

Python Learning simple web crawler

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.