测试设备
iPhone 7 Plus,iOS 11.3.1已越狱
需安装的插件
Python3.6 版本:3.6.4-6 源地址:https://mcapollo.github.io/Public/
NewTerm 2 版本:2.0,源地址:https://cydia.hbang.ws/
https://cydia.hbang.ws/
安装PIP和SSL证书
在NewTerm 2终端输入
su
后回车;-
默认密码为alpine,输入密码后回车进入root环境;
执行
python3 -m ensurepip
命令安装pip执行
bash /usr/local/lib/python3.6/install_certificates.command
安装SSL证书
运行Python脚本
安装完PIP后可以使用pip3 install package-name
命令安装第三方库,已知道支持的库,支持ipython、jieba、requests、bs4;
- 用Filza File Manager文件管理器在/var/mobile文件夹下创建Python脚本文件(如图demo.py);
- 编写python代码;
- 在NewTerm 2 中进入root环境,执行
python3 filename
命令(如图python3 demo.py);
参考例子:王者荣耀皮肤爬虫
在iPad上测试通过,下载的皮肤照片保存到var/mobile文件夹中,可以用Filza File Manager文件管理器查看
import json
import requests
class Hero:
skin_url_base = 'http://game.gtimg.cn/images/yxzj/img201606/skin/hero-info/{id}/{ename}-bigskin-{num}.jpg'
def __init__(self, hero_id, hero_name, hero_nickname, hero_skin_name):
"""
功能:
英雄初始化
参数:
hero_id {[str]} -- [英雄的id]
hero_name {[str]} -- [英雄名称]
hero_nickname {[str]} -- [英雄昵称]
hero_skin_name {[str]} -- [英雄皮肤名称,多款皮肤名称中间以‘|’隔开]
"""
self.hero_id = hero_id
self.hero_name = hero_name
self.hero_nickname = hero_nickname
self.hero_skin_name = hero_skin_name
def download_skin(self):
"""
功能:
下载英雄皮肤
"""
for num, i in enumerate(self.hero_skin_name.split('|')):
with open(self.hero_name + ' - ' + i + '.jpg', 'wb') as f:
resp = requests.get(self.skin_url_base.format(
id=self.hero_id, ename=self.hero_id, num=num+1))
f.write(resp.content)
print('{hero_name},共{count}款皮肤下载完成'.format(
hero_name=self.hero_name, count=len(self.hero_skin_name.split('|'))))
def __str__(self):
"""
功能:
用于print()打印英雄的详细信息
返回值:
[str] -- [重写__str__()方法,用于打印英雄的详细信息]
"""
return '英雄:{hero_name},昵称:{hero_nickname},ID:{hero_id},共有{count}款皮肤'.format(hero_name=self.hero_name, hero_nickname=self.hero_nickname, hero_id=self.hero_id, count=len(self.hero_skin_name.split('|')))
hero_list_url = "http://pvp.qq.com/web201605/js/herolist.json"
headers = {
'Accept-Encoding': "gzip, deflate",
'Accept-Language': "zh-CN,zh;q=0.9,en;q=0.8,zh-TW;q=0.7",
'User-Agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36",
'Content-Type': "application/json; charset=utf-8",
'Accept': "application/json, text/javascript, */*; q=0.01",
'Referer': "http://pvp.qq.com/web201605/herolist.shtml",
'X-Requested-With': "XMLHttpRequest",
'Connection': "keep-alive",
'Cache-Control': "no-cache",
}
response = requests.request("GET", hero_list_url, headers=headers)
datas = json.loads(response.text)
heros = [Hero(data['ename'], data['cname'], data['title'],
data['skin_name']) for data in datas]
# 计算王者荣耀总共有多少款皮肤
sum = sum([len(hero.hero_skin_name.split('|')) for hero in heros])
print('共{sum}款皮肤,开始下载···'.format(sum=sum))
for hero in heros:
hero.download_skin()
print('全部皮肤下载完成')