Skip to content

Instantly share code, notes, and snippets.

@zqqf16
Created Oct 15, 2018
Embed
What would you like to do?
Crawl iOS device models from https://www.theiphonewiki.com/wiki/Models
{
"i386": "Simulator",
"x86_64": "Simulator",
"iPad1,1": "iPad",
"iPad2,1": "iPad 2",
"iPad2,2": "iPad 2",
"iPad2,3": "iPad 2",
"iPad2,4": "iPad 2",
"iPad3,1": "iPad (3rd generation)",
"iPad3,2": "iPad (3rd generation)",
"iPad3,3": "iPad (3rd generation)",
"iPad3,4": "iPad (4th generation)",
"iPad3,5": "iPad (4th generation)",
"iPad3,6": "iPad (4th generation)",
"iPad4,1": "iPad Air",
"iPad4,2": "iPad Air",
"iPad4,3": "iPad Air",
"iPad5,3": "iPad Air 2",
"iPad5,4": "iPad Air 2",
"iPad6,7": "iPad Pro (12.9-inch)",
"iPad6,8": "iPad Pro (12.9-inch)",
"iPad6,3": "iPad Pro (9.7-inch)",
"iPad6,4": "iPad Pro (9.7-inch)",
"iPad6,11": "iPad (5th generation)",
"iPad6,12": "iPad (5th generation)",
"iPad7,1": "iPad Pro (12.9-inch, 2nd generation)",
"iPad7,2": "iPad Pro (12.9-inch, 2nd generation)",
"iPad7,3": "iPad Pro (10.5-inch)",
"iPad7,4": "iPad Pro (10.5-inch)",
"iPad7,5": "iPad (6th generation)",
"iPad7,6": "iPad (6th generation)",
"iPad2,5": "iPad mini",
"iPad2,6": "iPad mini",
"iPad2,7": "iPad mini",
"iPad4,4": "iPad mini 2",
"iPad4,5": "iPad mini 2",
"iPad4,6": "iPad mini 2",
"iPad4,7": "iPad mini 3",
"iPad4,8": "iPad mini 3",
"iPad4,9": "iPad mini 3",
"iPad5,1": "iPad mini 4",
"iPad5,2": "iPad mini 4",
"iPhone1,1": "iPhone",
"iPhone1,2": "iPhone 3G",
"iPhone2,1": "iPhone 3GS",
"iPhone3,1": "iPhone 4",
"iPhone3,2": "iPhone 4",
"iPhone3,3": "iPhone 4",
"iPhone4,1": "iPhone 4S",
"iPhone5,1": "iPhone 5",
"iPhone5,2": "iPhone 5",
"iPhone5,3": "iPhone 5c",
"iPhone5,4": "iPhone 5c",
"iPhone6,1": "iPhone 5s",
"iPhone6,2": "iPhone 5s",
"iPhone7,2": "iPhone 6",
"iPhone7,1": "iPhone 6 Plus",
"iPhone8,1": "iPhone 6s",
"iPhone8,2": "iPhone 6s Plus",
"iPhone8,4": "iPhone SE",
"iPhone9,1": "iPhone 7",
"iPhone9,3": "iPhone 7",
"iPhone9,2": "iPhone 7 Plus",
"iPhone9,4": "iPhone 7 Plus",
"iPhone10,1": "iPhone 8",
"iPhone10,4": "iPhone 8",
"iPhone10,2": "iPhone 8 Plus",
"iPhone10,5": "iPhone 8 Plus",
"iPhone10,3": "iPhone X",
"iPhone10,6": "iPhone X",
"iPhone11,8": "iPhone XR",
"iPhone11,2": "iPhone XS",
"iPhone11,6": "iPhone XS Max",
"iPhone11,4": "iPhone XS Max"
}
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''
Crawl iOS device models from https://www.theiphonewiki.com/wiki/Models
Usage:
python3 models.py > models.json
'''
import re
import json
import requests
def get_raw(url):
r = requests.get(url)
if r.status_code != 200:
return None
return r.text
def parse_models(regex, text):
result = {}
lastModel = ""
model_regex = re.compile(r'.*\d,\d')
for item in regex.findall(text):
if model_regex.match(item):
result[item] = lastModel
else:
lastModel = item
return result
def output(results):
string = json.dumps(results, indent=4)
print(string)
def main(url):
text = get_raw(url)
if not text:
print("Connect to url failed")
return
results = {'i386': 'Simulator', 'x86_64': 'Simulator'}
regexes = [
re.compile(r'rowspan.*(iPad[\w \(\)-.]*)'),
re.compile(r'rowspan.*(iPhone[\w \(\)-.]*)')
]
for regex in regexes:
models = parse_models(regex, text)
results.update(models)
output(results)
if __name__ == '__main__':
main('https://www.theiphonewiki.com/w/index.php?title=Models&action=edit')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment