{"id":150,"date":"2018-11-01T22:51:58","date_gmt":"2018-11-01T14:51:58","guid":{"rendered":"http:\/\/www.eait.co\/?p=150"},"modified":"2019-04-05T12:39:19","modified_gmt":"2019-04-05T04:39:19","slug":"%e4%bd%bf%e7%94%a8python%e4%b8%8b%e8%bd%bd%e8%8b%b1%e9%9b%84%e8%81%94%e7%9b%9f%e8%8b%b1%e9%9b%84%e5%9b%be%e7%89%87%ef%bc%88%e5%ad%a6%e4%b9%a0%e7%ae%80%e5%8d%95%e7%88%ac%e8%99%ab%ef%bc%89","status":"publish","type":"post","link":"https:\/\/notes.coremix.net\/?p=150","title":{"rendered":"\u4f7f\u7528python\u4e0b\u8f7d\u82f1\u96c4\u8054\u76df\u82f1\u96c4\u56fe\u7247\uff08\u5b66\u4e60\u7b80\u5355\u722c\u866b\uff09"},"content":{"rendered":"<p>\u6700\u8fd1\u521a\u5b66\u4e60\u7684python\u722c\u866b\uff0c\u6548\u679c\u8fd8\u53ef\u4ee5\uff0c\u4f7f\u7528\u4e86\u51e0\u79cd\u4f8b\u5b50\uff0c\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b<\/p>\n<p>import requests,re,json<\/p>\n<p>#\u4e3a\u4f55\u540d\u5b57\u548c\u56fe\u7247\u4e0d\u4e71<br \/>\n#\u83b7\u53d6js\u6e90\u4ee3\u7801\u548c\u82f1\u96c4id<br \/>\n#\u62fc\u63a5url\u5730\u5740<br \/>\n#\u83b7\u53d6\u4e0b\u8f7d\u56fe\u7247\u540d\u79f0<br \/>\n#\u4e0b\u8f7d\u56fe\u7247<\/p>\n<p>#\u5efa\u8bae\u4f7f\u7528\u9a7c\u5cf0\u547d\u540d\u6cd5\uff0c\u6ce8\u91ca\u5fc5\u987b(\u56e0\u4e3a\u4e0d\u4f46\u53ef\u4ee5\u5e2e\u52a9\u4e2a\u4eba\u7406\u89e3\uff0c\u5e76\u4e14\u5728\u590d\u4e60\u7684\u65f6\u5019\u53ef\u4ee5\u52a0\u6df1\u8bb0\u5fc6\uff0c\u81ea\u5df1\u5728\u56de\u770b\u7684\u65f6\u5019\u4e0d\u5fc5\u53bb\u4e00\u904d\u4e00\u904d\u7684\u53bb\u63a8\u6f14\u7b97\u6cd5\uff0c\u53e6\u5916\u7ed9\u522b\u4eba\u770b\u7684\u65f6\u5019\u4e5f\u5f88\u6e05\u6670\u6613\u61c2\uff0c\u636e\u8bf4\u6b27\u7f8e\u7684\u8f6f\u4ef6\u516c\u53f8\u5ba1\u6838\u6ce8\u91ca\u6bd4\u5ba1\u6838\u4ee3\u7801\u8fd8\u4e25\u683c\uff0c\u8fd9<br \/>\n#\u4e5f\u8bb8\u662f\u4ed6\u4eec\u5408\u4f5c\u5341\u5206\u9ad8\u6548\u5e76\u4e14\u8f6f\u4ef6\u5f00\u53d1\u5341\u5206\u5feb\u901f\u7684\u539f\u56e0\u5427\uff0c\u575a\u6301\u6bcf\u5929\u6ce8\u91ca\u4e00\u4e2a\uff0c\u987a\u4fbf\u590d\u4e60\u4ee3\u7801\uff0c\u6709\u7684\u4ee3\u7801\u8fd8\u8981\u6c42\u4f1a\u80cc\uff09<br \/>\ndef getLOLImages():#\uff08\u5b9a\u4e49\u83b7\u53d6\u56fe\u7247\u51fd\u6570\uff09<br \/>\n#\u83b7\u53d6js\u6e90\u4ee3\u7801<br \/>\nurl_js = &#8216;http:\/\/lol.qq.com\/biz\/hero\/champion.js&#8217;<br \/>\nres_js = requests.get(url_js).content #.text\u76f4\u63a5\u662f\u5b57\u7b26\u4e32 content\u4e00\u822c\u662f\u83b7\u53d6\u56fe\u7247\u548c\u89c6\u9891\u5185\u5bb9<\/p>\n<p>#\u8f6c\u6210\u5b57\u7b26\u4e32<br \/>\nhtml_js = res_js.decode()<br \/>\n#\u901a\u8fc7\u6b63\u5219\u5339\u914d\u82f1\u96c4ID<br \/>\nreq ='&#8221;keys&#8221;:(.*?),&#8221;data&#8221;:&#8217; # \u5176\u4e2d\u3002*\uff1f\u662f\u5339\u914d\u5168\u90e8\u7684\u610f\u601d<br \/>\nlist_js = re.findall(req, html_js) #\u6574\u7406\u51fa\u5e8f\u5217\uff0c\u8fd9\u6b65\u4e0b\u9762\u53ef\u4ee5print\u4e00\u4e0b\u770b\u770b<\/p>\n<p>#str _&gt;dict<br \/>\ndict_js = json.loads(list_js[0])<br \/>\n# print(dict_js)<br \/>\npic_list = []<br \/>\nfor key in dict_js:<br \/>\n# print(key,dict_js[key])<br \/>\n# http: \/\/ ossweb &#8211; img.qq.com \/ images \/ lol \/ web201310 \/ skin \/ big51000.jpg<\/p>\n<p>for i in range(30): #\u8fd9\u4e2afor\u6574\u7406\u4e0d\u5b58\u5728\u7684\u56fe\u7247<br \/>\nnum = str(i) #\u4e3a\u4ec0\u4e48num\u4e0d\u80fd\u7528<br \/>\nif len(num) == 1:<br \/>\nhero_num = &#8220;00&#8221;+ num #001<br \/>\nelif len(num) ==2:<br \/>\nhero_num = &#8220;0&#8221; + num #011<br \/>\nnumstr = key + hero_num<br \/>\n# print(numstr)<br \/>\ndownurl = &#8220;http:\/\/ossweb-img.qq.com\/images\/lol\/web201310\/skin\/big&#8221;+ numstr +&#8221;.jpg&#8221; #\u5f00\u59cb\u4e0b\u8f7d\u82f1\u96c4\u8054\u76df\u56fe\u7247<br \/>\n# print(downurl)<br \/>\npic_list.append(downurl)<br \/>\n#\u83b7\u53d6\u56fe\u7247\u4e0b\u8f7d\u540d\u79f0<br \/>\n# print(dict_js.keys())<br \/>\nlist_filepath = []<br \/>\npath = &#8220;C:\\\\LOL\\\\&#8221;<br \/>\nfor name in dict_js.values():<br \/>\nfor i in range(30):<br \/>\nfile_path = path + name + str(i)+&#8221;.jpg&#8221;<br \/>\n# print(file_path)<br \/>\nlist_filepath.append(file_path)<br \/>\n# print(list_filepath)<\/p>\n<p>#\u4e0b\u8f7d\u56fe\u7247<br \/>\nn = 0 #\u8fc7\u6ee4\u65e0\u6cd5\u4e0b\u8f7d\u7684\u56fe\u7247\uff0c\u8fd4\u56de200\u4e3a\u4e0d\u5b58\u5728\u7684\u56fe\u7247\uff0c\u6240\u4ee5\u987e\u8651\u6389<br \/>\nfor picurl in pic_list:<br \/>\nres = requests.get(picurl)<br \/>\n# print(res)<br \/>\nn +=1<br \/>\nif res.status_code == 200:<\/p>\n<p>print(&#8220;\u6b63\u5728\u4e0b\u8f7d:%s&#8221;%list_filepath[n])<br \/>\nprint(list_filepath[n])<br \/>\nprint(picurl)<br \/>\nf = open(list_filepath[n],&#8221;wb&#8221;)<br \/>\nf.write(res.content)<br \/>\nf.close<\/p>\n<p># print(res_js)<br \/>\ngetLOLImages()<\/p>\n<p>&nbsp;<\/p>\n<p>\u54ea\u91cc\u4e0d\u662f\u7279\u522b\u61c2\u53ef\u4ee5\u5728\u4e0b\u9762\u7559\u8a00\uff0c\u6211\u770b\u5230\u4f1a\u5c3d\u91cf\u56de\u590d\u7684<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u521a\u5b66\u4e60\u7684python\u722c\u866b\uff0c\u6548\u679c\u8fd8\u53ef\u4ee5\uff0c\u4f7f\u7528\u4e86\u51e0\u79cd\u4f8b\u5b50\uff0c\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b import requests,re, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,25,2,1],"tags":[],"class_list":["post-150","post","type-post","status-publish","format-standard","hentry","category-python","category-py","category-index","category-uncategorized"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/notes.coremix.net\/index.php?rest_route=\/wp\/v2\/posts\/150","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/notes.coremix.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/notes.coremix.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/notes.coremix.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/notes.coremix.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=150"}],"version-history":[{"count":2,"href":"https:\/\/notes.coremix.net\/index.php?rest_route=\/wp\/v2\/posts\/150\/revisions"}],"predecessor-version":[{"id":217,"href":"https:\/\/notes.coremix.net\/index.php?rest_route=\/wp\/v2\/posts\/150\/revisions\/217"}],"wp:attachment":[{"href":"https:\/\/notes.coremix.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=150"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/notes.coremix.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=150"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/notes.coremix.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=150"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}