{"id":515,"date":"2021-07-29T12:14:11","date_gmt":"2021-07-29T04:14:11","guid":{"rendered":"http:\/\/zero.xuyuanq.com\/?p=515"},"modified":"2021-07-29T12:14:11","modified_gmt":"2021-07-29T04:14:11","slug":"%e5%8a%a8%e6%80%81%e9%a1%b5%e9%9d%a2%e7%88%ac%e8%99%ab%ef%bc%9a%e6%8a%93%e5%8f%96%e8%8a%b1%e7%93%a3%e7%bd%91%e7%9a%84%e5%a6%b9%e5%ad%90%e5%9b%be%e7%89%87","status":"publish","type":"post","link":"https:\/\/martensite.xuyuanq.com\/?p=515","title":{"rendered":"\u52a8\u6001\u9875\u9762\u722c\u866b\uff1a\u6293\u53d6\u82b1\u74e3\u7f51\u7684\u59b9\u5b50\u56fe\u7247"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\u4ee5\u524d\u554a\uff0c\u4e00\u76f4\u641e\u4e0d\u660e\u767d\uff0c\u4e3a\u4ec0\u4e48\u4e92\u76f8\u559c\u6b22\u7684\u4e24\u4e2a\u4eba\uff0c\u5b83\u4e0d\u80fd\u4e00\u76f4\u8d70\u4e0b\u53bb\u3002\u73b0\u5728\u6211\u77e5\u9053\u4e86\u5440\u3002\u539f\u6765\u662f\u6709\u4e2a\u4eba\u5728\u6492\u8c0e<\/p><\/blockquote>\n\n\n\n<p>\u4e00\u4e2a\u5076\u7136\u7684\u673a\u4f1a\u53d1\u73b0\u4e86\u82b1\u74e3\u7f51\uff1a<a rel=\"noreferrer noopener\" href=\"https:\/\/huaban.com\/boards\/favorite\/beauty\/\" target=\"_blank\" rel=\"nofollow\" >\u7f8e\u5973\u56fe\u96c6_\u7f8e\u5973\u76f8\u518c_\u82b1\u74e3\u753b\u677f<\/a>&nbsp;\u8fd9\u4e2a\u795e\u5947\u7684\u7f51\u7ad9\uff0c\u59b9\u5b50\u56fe\u7247\u90fd\u662f\u6781\u597d\u7684\u3002\u8fd9\u5c82\u4e0d\u662f\u8bf1\u60d1\u7740\u6211\u7528\u4e2a\u722c\u866b\u6765\u9020\u4f5c\u4e00\u756a\u3002\uff08\u6ce8\u610f\u672c\u4eba\u7528\u7684\u662fpython\uff09<\/p>\n\n\n\n<p>\u901a\u8fc7\u5bf9\u7f51\u9875\u7684\u68c0\u67e5\uff0c\u53d1\u73b0\u8fd9\u662f\u4e00\u4e2a\u52a8\u6001\u52a0\u8f7d\u7684\u7f51\u7ad9\uff0c\u771f\u662f\u60b2\u4f24\u3002\u4e0d\u8fc7\u6ca1\u5173\u7cfb\uff0c\u5206\u6790\u4e00\u4e0b\u8bf7\u6c42\u89c4\u5f8b\uff0c\u8fd8\u662f\u53ef\u4ee5\u722c\u6ef4\u3002<\/p>\n\n\n\n<p>\u5206\u6790\u7f51\u9875\u89c4\u5f8b\uff0c\u6bcf\u4e2a\u56fe\u7247\u7684\u5206\u9875url \u90fd\u6709\u4e00\u4e2apin_id \uff0c\u62ff\u5230pin_id\u5c31\u53ef\u4ee5\u8fdb\u5165\u56fe\u7247\u7684\u8be6\u60c5\u9875\u9762\u4e86<\/p>\n\n\n\n<p>\u7ecf\u8fc7\u4e00\u756aF12\u6293\u5305\u53d1\u73b0\u4e86\u8bf7\u6c42url\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>http:&#47;&#47;huaban.com\/boards\/16115516\/?jawjlvud&amp;max=1339300078&amp;limit=20&amp;wfl=1<\/code><\/pre>\n\n\n\n<p>\u8fd9\u5c31\u662f\u5728\u67d0\u4e00\u4e2a\u753b\u677f\u4e0b\u7ee7\u7eed\u8bf7\u6c42\u7684url\uff0c\u53ef\u4ee5\u53d1\u73b0\uff0cmax=\u540e\u9762\u5c31\u662f\u67d0\u4e00\u56fe\u7247\u7684pin_id\uff0c\u53ef\u4ee5\u4e3a\u7a7a\uff0c\u5c31\u8fd4\u56de\u524d20\u4e2apin_id<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic3.zhimg.com\/80\/v2-4b6168ec7639f85d091d779df63f6636_720w.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u4ece\u9ad8\u91cf\u884c\u53d6\u51fajson\u6570\u636e\uff0c\u53ef\u4ee5\u770b\u5230\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic3.zhimg.com\/80\/v2-b76f902df293243f9c21c073496ce022_720w.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>pin_id\u5c31\u5728json\u6570\u636e\u4e2d\uff0c\u7ee7\u7eed\u52a0\u8f7d\u7684url\u4e2d\u7684max=\u53c2\u6570\u540e\u9762\u5c31\u662f\u6700\u540e\u4e00\u4e2apin_id\u3002\u90a3\u5c31\u6709\u601d\u8def\u4e86\uff1a\u901a\u8fc7\u4e0d\u65ad\u5730\u8bf7\u6c42\uff0c\u5c06\u8fd4\u56de\u7684\u6700\u540e\u4e00\u4e2apin_id\u4f5c\u4e3a\u4e0b\u4e00\u6b21\u8bf7\u6c42\u7684\u53c2\u6570\uff0c\u5c31\u53ef\u4ee5\u62ff\u5230\u6240\u6709\u7684pin_id\u4e86\u3002<\/p>\n\n\n\n<p>\u62ff\u5230\u4e86pin_id\uff0c\u8fdb\u5165\u5206\u9875\u53d1\u73b0\u8fd4\u56de\u7684\u4f9d\u7136\u662fhtml\u6587\u672c\uff0c\u62ff\u4e0d\u5230\u56fe\u7247<\/p>\n\n\n\n<p>\u53d1\u73b0\u56fe\u7247\u7684\u4e0b\u8f7d\u94fe\u63a5\u683c\u5f0f\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>url = 'http:\/\/img.hb.aicdn.com\/'+key+'_fw658'<\/code><\/pre>\n\n\n\n<p>\u8fd9\u4e2akey\u5c31\u5305\u542b\u5728\u8fd4\u56de\u7684html\u4e2d\u7684\u4e00\u4e2ajson\u683c\u5f0f\u7684\u5b57\u7b26\u4e32\u4e2d\uff0c\u63d0\u53d6\u51fa\u6765\u5c31\u597d\u4e86<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/pic2.zhimg.com\/80\/v2-ff36f4b308b031af87756dc6972d4795_720w.jpg\" alt=\"\"\/><\/figure>\n\n\n\n<p>\u4e0b\u9762\u662f\u5b8c\u6574\u7684\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import os\nimport requests\nimport jsonpath\n\nheaders = {'User-Agent':'Mozilla\/5.0 (Windows NT 10.0; WOW64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/62.0.3202.94 Safari\/537.36'\n           ,'Accept':'application\/json'\n           ,'X-Request':'JSON'\n           ,'X-Requested-With':'XMLHttpRequest'}\nheaders_img = {'User-Agent':'Mozilla\/5.0 (Windows NT 10.0; WOW64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/62.0.3202.94 Safari\/537.36'}\n\n\ndef save_img(pin_id_list):\n    #pin_id_list = opener(file_name)\n    dir_name = input(\"enter the dir_name :\")\n    #dir_name = \"huaban\"\n    try:\n        os.mkdir(dir_name)\n    except OSError as o:\n        print(o)\n        pass\n    os.chdir('E:\\pythonproject\\\u5f7c\u5cb8\u56fe\u5e93\\\u82b1\u74e3\u7f51\\%s' % dir_name)\n    for each in pin_id_list:\n        find_img(each)\n        #pin_id_list.remove(each)\n        print(\"%s is done.\"%each)\n    os.chdir('..')\n\n\ndef controlor(boards_id):\n\n    id_list = save_txt(boards_id)\n    save_img(id_list)\n\n\ndef save_txt(boards_id):\n    tuple_return = find_all_pin_id(boards_id)\n    #print(tuple_return)\n    id_list = tuple_return&#91;0]\n    pin_count = tuple_return&#91;1]\n\n    if len(id_list) == pin_count:\n        file_name = 'all_'+str(boards_id)+\".txt\"\n    else:\n        lack_nummber = str(pin_count-len(id_list))\n        file_name = 'lack_' + lack_nummber +\"_\"+ str(boards_id)+\".txt\"\n    with open(file_name,\"wb\")as f:\n        for each in id_list:\n            each = str(each) + ';'\n            txt = each.encode(encoding='utf-8')\n            f.write(txt)\n    print(\"\u5199\u5165boardsID\u5b8c\u6210\")\n    return id_list\n\n\ndef find_img(pin_id):\n    url = 'http:\/\/huaban.com\/pins\/%s\/?jaw2dlf8' %pin_id\n    # print(url)\n    rsp = requests.get(url, headers=headers)\n    #print(rsp.text)\n    json_obj = rsp.json()\n    img_key = jsonpath.jsonpath(json_obj, \"$..original_pin.file.key\")  # \u8fd9\u91cc\u5c31\u5b9a\u4f4d\u5230\u4e86\u56fe\u7247\u7684key\n    img_type = jsonpath.jsonpath(json_obj, '$..original_pin.file.type')  # \u987a\u4fbf\u628a\u56fe\u7247\u7684\u683c\u5f0f\u63d0\u53d6\u51fa\u6765\n    img_id = jsonpath.jsonpath(json_obj, \"$..pin_id\")&#91;0]\n    img_source = jsonpath.jsonpath(json_obj, \"$..source\")&#91;0]\n    img_link = jsonpath.jsonpath(json_obj, \"$..link\")&#91;0]\n    #print(img_source)\n    #print(img_link)\n\n    if img_key == False:\n        img_key = jsonpath.jsonpath(json_obj, \"$..file.key\")  # \u4e0a\u4e00\u6b65\u8fd4\u56de\u7684key\u6709\u4e00\u4e9b\u662fFalse\uff0c\u56e0\u4e3aoriginal\u53ef\u80fd\u4e3a\u7a7a\n        img_type = jsonpath.jsonpath(json_obj, '$..file.type')  # \u901a\u8fc7\u5206\u6790:\u6709\u4e00\u4e9b\u56fe\u7247\u7684key \u5728file\u76ee\u5f55\u4e0b\uff0c\u90a3\u5c31\u6539\u53d8\u4e00\u4e0b\u63d0\u53d6\u51fa\u6765\n    img_key = img_key&#91;0]\n    img_type = img_type&#91;0]\n    img_id = str(img_id)\n    i = img_type.index(\"\/\")\n    img_type = img_type&#91;i + 1:]\n    # print(img_type + ':' + img_key +':'+ img_id)\n    #return (img_key,img_id,img_type)\n    downloader(img_key,img_id,img_type)\n\n\ndef downloader(key,pin_id,type):\n    '''\u8fd9\u662f\u4e00\u4e2a\u4e0b\u8f7d\u5668\uff0c\u4f20\u5165\u4e09\u4e2a\u53c2\u6570\uff0c\u6784\u5efaurl\uff0c\u5f97\u5230\u56fe\u7247\uff0c\u4fdd\u5b58\uff01'''\n\n    url = 'http:\/\/img.hb.aicdn.com\/'+key+'_fw658'  # \u6784\u5efaurl\n    try:\n        img = requests.get(url,headers=headers).content\n        img_name = str(pin_id)+'.'+type\n        print(\"---------------------------------------------------------------------------------\")\n        print(\"\u6b63\u5728\u4e0b\u8f7d\u56fe\u7247\uff1a\" + img_name)\n        print(\"\u4e0b\u8f7d\u94fe\u63a5\uff1a\" + url)\n        with open(img_name,\"wb\")as f:  # \u5199\u5165\u6587\u4ef6\n            f.write(img)\n    except Exception as t:\n        with open(\"Error_logging.txt\",\"wb\")as w:\n            error = str(t)+\"\u51fa\u9519\u4e86\uff01\u56fe\u7247\u94fe\u63a5\u662f\uff1a\"+ url\n            w.write(error.encode(encoding=\"utf-8\"))  # \u8bb0\u5f55\u4e0b\u9519\u8bef\u65e5\u5fd7\n        pass\n\n\ndef find_pin_id_20(pin_id,boards_id):\n    request_URL = 'http:\/\/huaban.com\/boards\/%s\/?jbrvz3x1&amp;max=%s&amp;limit=20&amp;wfl=1'%(str(boards_id),str(pin_id))\n    print(request_URL)\n    json_obj = requests.get(request_URL,headers = headers).json()\n    #print(json_obj)\n    pin_id_list = jsonpath.jsonpath(json_obj, \"$..pin_id\")  # jsonpath\u65b9\u6cd5\u5339\u914d\u51fapinID\n\n    if pin_id_list != False:\n        #print(\"\u83b7\u53d6\u5230\u7684id\u4e2a\u6570:   \"+str(len(pin_id_list)))\n        int_list = &#91;]\n        for each in pin_id_list:\n            int_list.append(int(each))\n        #print(int_list)\n        return int_list\n    else:\n        return pin_id_list\n\n\ndef find_all_pin_id(boards_id):\n    url = 'http:\/\/huaban.com\/boards\/%s\/'%str(boards_id)\n    rsp = requests.get(url,headers=headers)\n    #print(rsp.text)\n    json_obj = rsp.json()\n    pin_count = jsonpath.jsonpath(json_obj, '$..pin_count')&#91;0]\n    pin_id_original = jsonpath.jsonpath(json_obj,'$..pin_id')\n    #print(len(pin_id_original))\n    while True:\n        if len(pin_id_original) &lt; 20:\n            break\n        else:\n            print(\"---------------------------------\")\n            #print(\"\u5f00\u59cb\u7684id:%s\"%pin_id_original&#91;-1])\n            new_list = find_pin_id_20(pin_id_original&#91;-1],boards_id)\n            print(\"\u8fd4\u56de\u7684id:%s\"%new_list)\n        if new_list == False:\n            break\n        if new_list == None:\n            break\n        pin_id_original.extend(new_list)\n        if len(new_list) &lt;20:\n            break\n    check_list = &#91;]\n    for each in pin_id_original:\n        if each not in check_list:\n            check_list.append(each)\n    #print(len(check_list))\n    return (check_list,pin_count)\n\n\nif __name__ == \"__main__\":\n    boards_id = input(\"\u8bf7\u8f93\u5165\u753b\u677fid\uff1a\")\n    controlor(int(boards_id))<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/zero.xuyuanq.com\/wp-content\/uploads\/2021\/07\/\u5c0f\u7a0b\u5e8f\u4e91\u8776\u8c37.gif\" alt=\"\" class=\"wp-image-516\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u4ee5\u524d\u554a\uff0c\u4e00\u76f4\u641e\u4e0d\u660e\u767d\uff0c\u4e3a\u4ec0\u4e48\u4e92\u76f8\u559c\u6b22\u7684\u4e24\u4e2a\u4eba\uff0c\u5b83\u4e0d\u80fd\u4e00\u76f4\u8d70\u4e0b\u53bb\u3002\u73b0\u5728\u6211\u77e5\u9053\u4e86\u5440\u3002\u539f\u6765\u662f\u6709\u4e2a\u4eba\u5728\u6492\u8c0e \u4e00\u4e2a\u5076\u7136\u7684\u673a\u4f1a\u53d1\u73b0\u4e86\u82b1\u74e3\u7f51\uff1a\u7f8e &#8230;<\/p>\n","protected":false},"author":2,"featured_media":884,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[32,37],"tags":[45],"class_list":["post-515","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-courses","category-codes","tag-45"],"_links":{"self":[{"href":"https:\/\/martensite.xuyuanq.com\/index.php?rest_route=\/wp\/v2\/posts\/515","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/martensite.xuyuanq.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/martensite.xuyuanq.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/martensite.xuyuanq.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/martensite.xuyuanq.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=515"}],"version-history":[{"count":0,"href":"https:\/\/martensite.xuyuanq.com\/index.php?rest_route=\/wp\/v2\/posts\/515\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/martensite.xuyuanq.com\/index.php?rest_route=\/"}],"wp:attachment":[{"href":"https:\/\/martensite.xuyuanq.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=515"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/martensite.xuyuanq.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=515"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/martensite.xuyuanq.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=515"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}