mac下爬虫实验
安装 Python安装 Pip安装 BeautifulSoup#!/usr/bin/python#-*- coding: utf-8 -*-#encoding=utf-8import urllib2import urllibimport osfrom bs4 import BeautifulSoup##defdef getA
·
安装 Python
安装 Pip
sudo easy_install pip
安装 BeautifulSoup
#!/usr/bin/python
#-*- coding: utf-8 -*-
#encoding=utf-8
import urllib2
import urllib
import os
from bs4 import BeautifulSoup
#
#def
def getAllImageLink():
i=1;
#while
while(i<2):
#http://www.dbmeizi.com/category/11?p=0
#html = urllib2.urlopen('http://www.dbmeizi.com/category/11?p=%s'%(i-1)).read()
html = urllib2.urlopen('http://www.jczj123.net/index2.htm')
i=i+1;
#html = urllib2.urlopen('http://www.dbmeizi.com').read()
soup = BeautifulSoup(html, "lxml")
#
liResult = soup.findAll('img')
m=0
print liResult
for li in liResult:
m=m+1
print("linkk")
imageEntityArray = li
#find img
link=li.get('src')
#print(link)
imageName=m
filesavepath ='/Users/apple/Desktop/testpy/%s.jpg' % imageName
value=link.split('http')
if len(value)> 1:
urllib.urlretrieve(link,filesavepath)
print filesavepath
if __name__ == '__main__':
getAllImageLink()
更多推荐
已为社区贡献1条内容
所有评论(0)