How to Use Reptile for iOS Programmer

Just find a funny article about iOS programmer to write reptile, everyone, just for fun, I will not be responsibility for any issue in law. html

Use the code with Python, you can do it, so please learn python! node

#!/usr/bin/python
#-*- coding: utf-8 -*-
#encoding=utf-8
import urllib2
import urllib
import os
from BeautifulSoup import BeautifulSoup
def getAllImageLink():
    html = urllib2.urlopen('http://www.dbmeizi.com').read()
    soup = BeautifulSoup(html)
    liResult = soup.findAll('li',attrs={"class":"span3"})
    for li in liResult:
        imageEntityArray = li.findAll('img')
        for image in imageEntityArray:
            link = image.get('data-src')
            imageName = image.get('data-id')
            filesavepath = '/Users/weihua0618/Desktop/meizipicture/%s.jpg' % imageName 
            urllib.urlretrieve(link,filesavepath)
            print filesavepath 
if __name__ == '__main__':
    getAllImageLink()
You should modify the file's path wrote in the code, also you should create the directory in the path, otherwise you will get some error like this:
Traceback (most recent call last):
  File "pictures.py", line 21, in <module>
    getAllImageLink()
  File "pictures.py", line 9, in getAllImageLink
    html = urllib2.urlopen('http://www.dbmeizi.com').read()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 127, in urlopen
    return _opener.open(url, data, timeout)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 404, in open
    response = self._open(req, data)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 422, in _open
    '_open', req)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 382, in _call_chain
    result = func(*args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1214, in http_open
    return self.do_open(httplib.HTTPConnection, req)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1184, in do_open
    raise URLError(err)
urllib2.URLError: <urlopen error [Errno 8] nodename nor servname provided, or not known>

Reference: python

http://www.cocoachina.com/programmer/20150227/11198.html python2.7

Good luck! ide


BUT, this way for getting info from network is important, we can use it in the project. For example, we can use it to get many pictures( or the other resource, e.g: novel, joke etc ), and save them into the database, then we can use it in many clients, oh, god, it is a new door for me! this

相關文章
相關標籤/搜索