{"id":66305,"date":"2020-04-15T14:54:08","date_gmt":"2020-04-15T06:54:08","guid":{"rendered":"http:\/\/4563.org\/?p=66305"},"modified":"2020-04-15T14:54:08","modified_gmt":"2020-04-15T06:54:08","slug":"%e5%86%99%e4%ba%86%e4%b8%aa%e6%bc%ab%e7%94%bb%e4%b8%8b%e8%bd%bd%e7%9a%84%e8%84%9a%e6%9c%ac","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=66305","title":{"rendered":"\u5199\u4e86\u4e2a\u6f2b\u753b\u4e0b\u8f7d\u7684\u811a\u672c"},"content":{"rendered":"\n<p>  \t\t\t\t\t<strong>oldj<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3>\u5199\u4e86\u4e2a\u6f2b\u753b\u4e0b\u8f7d\u7684\u811a\u672c<\/h3>\n<p>  \t\t\u63a5https:\/\/www.hostloc.com\/thread-674260-1-1.html<br \/>  \u56e0\u4e3a\u770b\u8001\u54e5\u4e00\u76f4\u6ca1\u53d1\u51fa\u6765\uff0c\u6240\u4ee5\u5c31\u5199\u4e86\u4e00\u4e2a\u811a\u672c\u4e0b\u8f7d<br \/>  \u652f\u6301\u591a\u7ebf\u7a0b\u4e0b\u8f7d<br \/>  \u6ce8\u610f\u4f7f\u7528\u524d\u4fee\u6539json_url\u4e3ajson\u5730\u5740<br \/>  \u811a\u672c\u4e0b\u8f7d\u5730\u5740<br \/>  https:\/\/github.com\/tusik\/json-parser-downloader\/blob\/master\/process.py<br \/>  https:\/\/raw.githubusercontent.com\/tusik\/json-parser-downloader\/master\/process.py<br \/>  \u5982\u679c\u51fa\u73b0\u521b\u5efa\u76ee\u5f55\u7684\u7f16\u7801\u62a5\u9519\uff0c\u8bf7\u6ce8\u610f\u8bbe\u7f6e\u73af\u5883\u7f16\u7801\u4e3autf8<br \/>  # -*- coding: UTF-8 -*-<br \/>  import psycopg2<br \/>  import requests<br \/>  import sys,json,os<br \/>  from threading import Thread<\/p>\n<p>  def download_img(path,url):<br \/>  &nbsp; &nbsp; r = requests.get(url, headers=headers)<br \/>  &nbsp; &nbsp; filename_t = str(url).split(&#8216;\/&#8217;)<br \/>  &nbsp; &nbsp; filename = filename_t<br \/>  &nbsp; &nbsp; with open(path+&#8217;\/&#8217;+filename, &#8216;wb&#8217;) as f:<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;f.write(r.content)<\/p>\n<p>  headers = {<br \/>  &nbsp; &nbsp; &#8216;User-Agent&#8217;: &#8216;Mozilla\/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit\/537.36 (KHTML, like Gecko) &#8216;<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&#8216;Chrome\/80.0.3987.149 Safari\/537.36 &#8216;<br \/>  }<br \/>  title = &#8221;<br \/>  json_url = &#8221;<br \/>  if not os.path.exists(&quot;export.json&quot;):<br \/>  &nbsp; &nbsp; r = requests.get(json_url, stream=True)<br \/>  &nbsp; &nbsp; f = open(&quot;export.json&quot;, &quot;wb&quot;)<br \/>  &nbsp; &nbsp; for chunk in r.iter_content(chunk_size=512):<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;if chunk:<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;f.write(chunk)<br \/>  with open(&quot;export.json&quot;,&quot;r&quot;,encoding=&#8217;utf-8&#8242;) as data:<br \/>  &nbsp; &nbsp; json_obj = json.load(data)<\/p>\n<p>  for i in json_obj:<br \/>  &nbsp; &nbsp; title = i[&#8216;title&#8217;]<br \/>  &nbsp; &nbsp; if not os.path.exists(title):<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;os.mkdir(title)<\/p>\n<p>  &nbsp; &nbsp; r = requests.get(i[&#8216;cover&#8217;], headers=headers)<br \/>  &nbsp; &nbsp; with open(i[&#8216;title&#8217;]+&quot;\/cover.jpg&quot;, &#8216;wb&#8217;) as f:<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;f.write(r.content)<\/p>\n<p>  &nbsp; &nbsp; chaper = &#8221;<br \/>  &nbsp; &nbsp; for k in i[&#8216;chapters&#8217;]:<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;threads = []<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;cp_title = k[&#8216;title&#8217;]<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;if not os.path.exists(title+&#8217;\/&#8217;+cp_title):<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;os.mkdir(title+&#8217;\/&#8217;+cp_title)<\/p>\n<p>  &nbsp; &nbsp;&nbsp; &nbsp;print(&#8216;Downloading &#8216; + cp_title)<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;for j in k[&#8216;images&#8217;]:<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;t = Thread(target=download_img,args=)<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;t.start()<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;threads.append(t)<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;for t in threads:<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;t.join()<\/p>\n<p>  \t\t\t\t\t<strong>b66667777<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\t\u611f\u8c22\u5206\u4eab&nbsp; &nbsp;\t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>C\u5927<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\t\u8c22\u8c22\uff01\t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>\u590f\u6e14<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\t\u611f\u8c22\u5206\u4eab\t\t\t  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>oldj \u5927\u4f6c\u6709\u8bdd\u8bf4 : \u5199\u4e86\u4e2a\u6f2b&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/66305"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=66305"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/66305\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=66305"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=66305"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=66305"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}