How to Use Reptile for iOS Programmer
How to Use Reptile for iOS Programmer
BluesChow 发表于3年前
How to Use Reptile for iOS Programmer
  • 发表于 3年前
  • 阅读 20
  • 收藏 0
  • 点赞 0
  • 评论 0

腾讯云 新注册用户 域名抢购1元起>>>   

摘要: Reptile, iOS, Python

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.

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

#!/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:

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

Good luck!


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!

共有 人打赏支持
粉丝 6
博文 143
码字总数 29622
×
BluesChow
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: