import multiprocessing
import requests
import os
import re
import json
import getpass
array = []
def get_page(url):
respone = requests.get(url)
if respone.status_code == 200:
return respone.text
return ""
def pasrse_page(urlStr):
hexStrings = re.findall(',"color-hex":"#(.*?) 100%",',urlStr,re.S)
for hexString in hexStrings:
hexString = json.dumps(hexString, ensure_ascii=False, encoding='UTF-8')
hexString = hexString.replace('"','')
if len(hexString) > 6:
continue
outStr = hexString+' '+hexString
if outStr not in array:
array.append(outStr.encode("utf-8"))
def writeStringToFile(writeString, filePath):
optStr = 'w'
if os.path.isfile(filePath):
optStr = 'a'
print optStr
with open(filePath, optStr) as f:
f.write(writeString)
if __name__ == '__main__':
urls = [一大堆url地址]
p = multiprocessing.Pool(3)
res_list = []
for url in urls:
res = p.apply_async(get_page, args=(url,), callback=pasrse_page)
res_list.append(res)
p.close()
p.join()
ab = set(array)
outStr = '\n'.join(ab)
filePath = '/Users/%s/Desktop/color.txt'%getpass.getuser()
writeStringToFile(outStr, filePath)
os.system('/Users/mac/Downloads/ColorTools-0.3/Html2Clr /Users/mac/Desktop/color.txt')
会用到这个,将输出的字符串,转换成clr文件
Xcode里就能愉快地使用了