zoukankan      html  css  js  c++  java
  • Python 实现网络爬虫小程序

    Python很简洁,也很强大,作为兴趣,值得一学!

     

    下面这个程序实现的是从一个网站上下载图片,根据自己需要可以进行修改

     1 import re
     2 import urllib
     3 
     4 def gethtml(url):
     5     page = urllib.urlopen(url)
     6     html = page.read()
     7     return html
     8 
     9 def getimg(html):
    10     reg = r'src="(.*?.jpg)"'
    11     imgre = re.compile(reg)
    12     imglist = re.findall(imgre, html)
    13     x = 1
    14     for imgurl in imglist:
    15         urllib.urlretrieve(imgurl, '%s.jpg' % x)
    16         x+=1
    17 
    18 target = raw_input("Input one url:")
    19 html =  gethtml(target)
    20 print "please wating, pictrues are downloading....."
    21 getimg(html)
  • 相关阅读:
    如何为创建大量实例节省内存?
    4-5
    4-6
    4-4
    4-3
    4-2
    3-11
    4-1
    3-10
    3-8
  • 原文地址:https://www.cnblogs.com/anhuizhiye/p/3509619.html
Copyright © 2011-2022 走看看