{"id":2508,"date":"2022-08-08T10:54:30","date_gmt":"2022-08-08T02:54:30","guid":{"rendered":"http:\/\/cnliutz.uicp.io\/?p=2508"},"modified":"2022-08-08T10:54:30","modified_gmt":"2022-08-08T02:54:30","slug":"%e4%b8%8b%e8%bd%bd%e6%9f%90%e4%b8%aa%e7%bd%91%e9%a1%b5%e7%9a%84%e5%9b%be%e7%89%87","status":"publish","type":"post","link":"http:\/\/g1n29wqq.ipyingshe.net:5347\/?p=2508","title":{"rendered":"\u4e0b\u8f7d\u67d0\u4e2a\u7f51\u9875\u7684\u56fe\u7247"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code># from urllib import request\n# import requests\n# rs =requests.get('http:\/\/cnliutz.uicp.io')\n# with open('cnliutz.txt','w+',encoding=\"utf-8\") as f:\n#     f.write(rs.text)\n#     print(f.readlines())\n# r = requests.get('https:\/\/www.baidu.com\/img\/bd_logo1.png')\n# with open('baidu.png', 'wb') as fp:\n#     fp.write(r.content)\nfrom bs4 import BeautifulSoup\nimport requests\n#import re\nimport os\n#import time\n#import random\n#import urllib.request\n\ndef get_html(url):\n    try:\n        r = requests.get(url, timeout=30)\n        r.raise_for_status()\n        r.encoding = r.apparent_encoding\n        return r.text\n    except:\n        return \"ERROR\"  \n\ndef get_content(url):\n    html = get_html(url)\n    soup = BeautifulSoup(html, 'lxml')\n    img = soup.find_all('img', class_ = \"headerimage\") #\u5728\u7f51\u9875\u4e2d\uff0c\u6309F12\uff0c\u627e\u5230\u6240\u6709\u7684img\u6807\u7b7e,\u66f4\u6539\u672c\u884cclass_ = \"headerimage\"\uff0c\u5373\u53ef\u4e0b\u8f7d\u5176\u4ed6\u56fe\u7247 \n    return img\n\ndef save_img(img):\n    for i in img:\n        img_url = i&#91;'src']\n        name = img_url.split('\/')&#91;-1]\n        with open(name, 'wb') as f:\n            img = requests.get(img_url).content\n            f.write(img)\n            print('\u6b63\u5728\u4fdd\u5b58\u56fe\u7247\uff1a', name)   \n\ndef main():\n    url = \"http:\/\/cnliutz.uicp.io\"\n    img = get_content(url)\n    save_img(img) \n\nif __name__ == '__main__':\n    main()\n    #url = \"http:\/\/cnliutz.uicp.io\"\n    # print(get_html(url))\n    print(os.getcwd())\n\n\n#\u4ee5\u4e0a\u4ee3\u7801win11\uff0cpython 3.8.5\u8c03\u8bd5\u901a\u8fc7\uff0c\u8bf7\u63d0\u524d\u5b89\u88c5beautifulsoup4\uff0crequests\u4e24\u4e2a\u5e93\u3002\npip install beautifulsoup4\uff0crequests  -i http:\/\/pypi.douban.com\/simple\n\n\n\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-2508","post","type-post","status-publish","format-standard","hentry","category-2"],"_links":{"self":[{"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/2508","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2508"}],"version-history":[{"count":0,"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/2508\/revisions"}],"wp:attachment":[{"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2508"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2508"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2508"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}