{"id":808,"date":"2023-05-23T17:47:41","date_gmt":"2023-05-23T09:47:41","guid":{"rendered":"https:\/\/kuo.us.to\/wordpress\/?p=808"},"modified":"2023-05-23T17:47:43","modified_gmt":"2023-05-23T09:47:43","slug":"python%e5%ad%b8%e7%bf%92%e7%ad%86%e8%a8%98-%e6%89%b9%e6%ac%a1%e5%b0%87%e6%aa%94%e6%a1%88%e5%90%8d%e7%a8%b1%e4%bf%ae%e6%94%b9%e7%82%ba%e8%87%aa%e5%8b%95%e4%b8%ad%e6%96%87%e5%a7%93%e5%90%8d_%e6%8f%90","status":"publish","type":"post","link":"https:\/\/kuo.us.to\/wordpress\/python%e5%ad%b8%e7%bf%92%e7%ad%86%e8%a8%98\/808\/","title":{"rendered":"Python\u5b78\u7fd2\u7b46\u8a18: \u6279\u6b21\u5c07\u6a94\u6848\u540d\u7a31\u4fee\u6539\u70ba\u81ea\u52d5\u4e2d\u6587\u59d3\u540d_\u63d0\u4f9b\u672a\u4f86\u793a\u7bc4\u4f7f\u7528"},"content":{"rendered":"\n<p>\u672c\u6587\u4e3b\u8981\u662f\u5de5\u4f5c\u4e0a\u4e00\u4e9b\u8cc7\u6599\u7528Python\u7a0b\u5f0f\u89e3\u6c7a\u5f8c\u60f3\u505a\u7684\u5206\u4eab\uff0c<br>\u4f46\u56e0\u70ba\u6a94\u6848\u8cc7\u6599\u7b49\u4e0d\u4fbf\u65bc\u7db2\u8def\u516c\u958b\uff0c<br>\u6240\u4ee5\u5c31\u7528Python\u5148\u5c07\u6a94\u6848\u540d\u7a31\u4fee\u6539\u4e00\u4e0b\uff0c<br>\u4ee5\u4fbf\u65bc\u65e5\u5f8c\u904b\u7528\u8207\u5206\u4eab\u3002<\/p>\n\n\n\n<p>\u539f\u59cb\u8cc7\u6599\u593e\u6a94\u6848\u72c0\u6cc1\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"666\" height=\"847\" src=\"https:\/\/kuo.us.to\/wordpress\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-23-01.jpg\" alt=\"\" class=\"wp-image-809\" srcset=\"https:\/\/kuo.us.to\/wordpress\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-23-01.jpg 666w, https:\/\/kuo.us.to\/wordpress\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-23-01-236x300.jpg 236w\" sizes=\"(max-width: 666px) 100vw, 666px\" \/><\/figure>\n\n\n\n<p>\u4ee5\u4e0b\u70ba\u7a0b\u5f0f\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport glob\nimport os\nimport re\npath = 'd:\\\\temp\\\\test\\\\'\nfiles = glob.glob(path + '*')\nprint(files)\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"439\" src=\"https:\/\/kuo.us.to\/wordpress\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-23-02-1024x439.jpg\" alt=\"\" class=\"wp-image-810\" srcset=\"https:\/\/kuo.us.to\/wordpress\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-23-02-1024x439.jpg 1024w, https:\/\/kuo.us.to\/wordpress\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-23-02-300x129.jpg 300w, https:\/\/kuo.us.to\/wordpress\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-23-02-768x329.jpg 768w, https:\/\/kuo.us.to\/wordpress\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-23-02.jpg 1167w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>\u63a5\u4e0b\u4f86\u662f\u7528\u4ee5\u524d\u5206\u4eab\u904e\u7684\u4e2d\u6587\u59d3\u540d\u81ea\u52d5\u7522\u751f\u5668\u722c\u87f2\uff0c\u81ea\u52d5\u7522\u751f\u4e2d\u6587\u59d3\u540d\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport requests\nimport pandas as pd\n\n# \u8a2d\u5b9atime\u70ba\u7372\u53d6\u4e2d\u6587\u59d3\u540d100\u7b46\u7684\u500d\u6578\u3002time=3\uff0c\u5c31\u662f300\u7b46\u7684\u610f\u601d\u3002\ntimes = 1\ncnames = &#x5B;]\nfor x in range(times):\n    url = 'http:\/\/www.richyli.com\/name\/index.asp'\n    r = requests.get(url)\n    r.encoding = 'big5'\n    \n    # \u5c07\u7db2\u9801\u4e2d\u7684\u8cc7\u6599\u4ee5\u5206\u884c\u7684\u65b9\u5f0f\u5b58\u6210\u6587\u5b57\u6a94\n    result = r.text.splitlines()\n    \n    # 114\u662f\u4e2d\u6587\u59d3\u540d\u958b\u59cb\u7684\u5217\uff0c\u627e\u5230\u6700\u5f8c\u4e00\u500b\u300c\u3001\u300d\uff0c\u8a2d\u5b9a\u6210\u70ba\u5b57\u4e32\u7684\u5207\u7247\u4f4d\u7f6e\u3002\n    char_index = result&#x5B;114].rfind(&quot;\u3001&quot;)\n    temp = result&#x5B;114]&#x5B;:char_index]\n    \n    # \u5c07temp\u7684100\u7b46\u59d3\u540d\u65b0\u589e\u5230cnames\u4e2d\n    cnames.append(temp)\n\n# \u5c07\u6bcf100\u7b46\u59d3\u540d\u7684list\u52a0\u4e00\u500b\u300c\u3001\u300d\uff0c\u518d\u7d44\u5408\u6210\u5b57\u4e32\u5b58\u5230my_names\u4e2d\nmy_names = &quot;\u3001&quot;.join(str(x) for x in cnames)\nprint(my_names)\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"118\" src=\"https:\/\/kuo.us.to\/wordpress\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-23-03-1024x118.jpg\" alt=\"\" class=\"wp-image-811\" srcset=\"https:\/\/kuo.us.to\/wordpress\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-23-03-1024x118.jpg 1024w, https:\/\/kuo.us.to\/wordpress\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-23-03-300x34.jpg 300w, https:\/\/kuo.us.to\/wordpress\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-23-03-768x88.jpg 768w, https:\/\/kuo.us.to\/wordpress\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-23-03.jpg 1158w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n# \u5c07\u4e0a\u9762\u7684\u59d3\u540d\u751f\u6210dataframe\ndf_name = pd.DataFrame(my_names.split('\u3001'), columns=&#x5B;'\u59d3\u540d'])\nprint(f'\u4e2d\u6587\u59d3\u540d\u7b46\u6578\uff1a{len(df_name)}')\n\n# \u5c07\u59d3\u540d\u505a\u6210list\nmy_list = df_name.\u59d3\u540d.values.tolist()\nprint(my_list)\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"172\" src=\"https:\/\/kuo.us.to\/wordpress\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-23-04-1024x172.jpg\" alt=\"\" class=\"wp-image-812\" srcset=\"https:\/\/kuo.us.to\/wordpress\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-23-04-1024x172.jpg 1024w, https:\/\/kuo.us.to\/wordpress\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-23-04-300x50.jpg 300w, https:\/\/kuo.us.to\/wordpress\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-23-04-768x129.jpg 768w, https:\/\/kuo.us.to\/wordpress\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-23-04.jpg 1168w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n# \u5c07\u6a94\u540d\u7528regex\u5206\u6210\u4e09\u7d44\uff0c\u7b2c\u4e00\u7d44\u70ba\u300c\u9644\u4ef6X-X\u300d\uff0c\u7b2c\u4e8c\u7d44\u70ba\u300c\u9644\u4ef6X-X\u5f8c\u9762\u7684\u5176\u4ed6\u6a94\u540d\u300d\uff0c\u7b2c\u4e09\u7d44\u70ba\u300c.\u9644\u6a94\u540d\u300d\npattern = '(\u9644\u4ef6\\d+-\\d)(.+)(\\..+)'\nn = 0\nfor file in files:\n    file_name = re.findall(pattern, file)\n    #print(file_name)\n    # \u5c07\u6a94\u540d\u524d\u9762\u7684\u9644\u4ef6X-X\u4fdd\u7559\uff0c\u7136\u5f8c\u52a0\u5165&quot;_&quot;\uff0c\u518d\u52a0\u5165\u4e2d\u6587\u81ea\u52d5\u7684\u59d3\u540d\uff0c\u518d\u52a0\u4e0a\u9644\u6a94\u540d\n    new_file_name = file_name&#x5B;0]&#x5B;0] + '_' + my_list&#x5B;n] + file_name&#x5B;0]&#x5B;2]\n    os.rename(file, path + new_file_name)\n    print(f'{file}\u5df2\u5b8c\u6210')\n    n += 1\n<\/pre><\/div>\n\n\n<p>d:\\temp\\test\\\u9644\u4ef61-1\u9019\u662f\u793a\u7bc4\u6a94\u6848\u9019\u662f\u793a\u7bc4\u6a94\u6848.docx\u5df2\u5b8c\u6210<br>\u2026<br>\u2026<br>\u4ee5\u4e0b\u7565\u3002<\/p>\n\n\n\n<p>\u6700\u5f8c\u8f38\u51fa\u7d50\u679c\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"312\" height=\"743\" src=\"https:\/\/kuo.us.to\/wordpress\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-23-05.jpg\" alt=\"\" class=\"wp-image-813\" srcset=\"https:\/\/kuo.us.to\/wordpress\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-23-05.jpg 312w, https:\/\/kuo.us.to\/wordpress\/wp-content\/uploads\/2023\/05\/Screenshot-2023-05-23-05-126x300.jpg 126w\" sizes=\"(max-width: 312px) 100vw, 312px\" \/><\/figure>\n\n\n\n<p>\u4ee5\u4e0a\u5373\u5b8c\u6210\u672c\u6b21\u76ee\u6a19\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u4e3b\u8981\u662f\u5de5\u4f5c\u4e0a\u4e00\u4e9b\u8cc7\u6599\u7528Python\u7a0b\u5f0f\u89e3\u6c7a\u5f8c\u60f3\u505a\u7684\u5206\u4eab\uff0c\u4f46\u56e0\u70ba\u6a94\u6848\u8cc7\u6599\u7b49\u4e0d\u4fbf\u65bc\u7db2\u8def\u516c\u958b\uff0c\u6240\u4ee5\u5c31\u7528Pytho [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":815,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advgb_blocks_editor_width":"","advgb_blocks_columns_visual_guide":"","site-sidebar-layout":"default","site-content-layout":"default","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}}},"categories":[4],"tags":[9,400,399],"author_meta":{"display_name":"mackuo","author_link":"https:\/\/kuo.us.to\/wordpress\/author\/mackuo\/"},"featured_img":"https:\/\/kuo.us.to\/wordpress\/wp-content\/uploads\/2023\/05\/fwvo1x7ckty-300x169.jpg","coauthors":[],"tax_additional":{"categories":{"linked":["<a href=\"https:\/\/kuo.us.to\/wordpress\/category\/python%e5%ad%b8%e7%bf%92%e7%ad%86%e8%a8%98\/\" class=\"advgb-post-tax-term\">Python\u5b78\u7fd2\u7b46\u8a18<\/a>"],"unlinked":["<span class=\"advgb-post-tax-term\">Python\u5b78\u7fd2\u7b46\u8a18<\/span>"]},"tags":{"linked":["<a href=\"https:\/\/kuo.us.to\/wordpress\/category\/python%e5%ad%b8%e7%bf%92%e7%ad%86%e8%a8%98\/\" class=\"advgb-post-tax-term\">Python<\/a>","<a href=\"https:\/\/kuo.us.to\/wordpress\/category\/python%e5%ad%b8%e7%bf%92%e7%ad%86%e8%a8%98\/\" class=\"advgb-post-tax-term\">\u4e2d\u6587\u59d3\u540d\u81ea\u52d5\u7522\u751f<\/a>","<a href=\"https:\/\/kuo.us.to\/wordpress\/category\/python%e5%ad%b8%e7%bf%92%e7%ad%86%e8%a8%98\/\" class=\"advgb-post-tax-term\">\u6279\u6b21\u66f4\u6539\u6a94\u540d<\/a>"],"unlinked":["<span class=\"advgb-post-tax-term\">Python<\/span>","<span class=\"advgb-post-tax-term\">\u4e2d\u6587\u59d3\u540d\u81ea\u52d5\u7522\u751f<\/span>","<span class=\"advgb-post-tax-term\">\u6279\u6b21\u66f4\u6539\u6a94\u540d<\/span>"]}},"comment_count":"0","relative_dates":{"created":"Posted 3 \u5e74 ago","modified":"Updated 3 \u5e74 ago"},"absolute_dates":{"created":"Posted on 2023 \u5e74 5 \u6708 23 \u65e5","modified":"Updated on 2023 \u5e74 5 \u6708 23 \u65e5"},"absolute_dates_time":{"created":"Posted on 2023 \u5e74 5 \u6708 23 \u65e5 \u4e0b\u5348 5:47","modified":"Updated on 2023 \u5e74 5 \u6708 23 \u65e5 \u4e0b\u5348 5:47"},"featured_img_caption":"","series_order":"","_links":{"self":[{"href":"https:\/\/kuo.us.to\/wordpress\/wp-json\/wp\/v2\/posts\/808"}],"collection":[{"href":"https:\/\/kuo.us.to\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kuo.us.to\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kuo.us.to\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kuo.us.to\/wordpress\/wp-json\/wp\/v2\/comments?post=808"}],"version-history":[{"count":1,"href":"https:\/\/kuo.us.to\/wordpress\/wp-json\/wp\/v2\/posts\/808\/revisions"}],"predecessor-version":[{"id":814,"href":"https:\/\/kuo.us.to\/wordpress\/wp-json\/wp\/v2\/posts\/808\/revisions\/814"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kuo.us.to\/wordpress\/wp-json\/wp\/v2\/media\/815"}],"wp:attachment":[{"href":"https:\/\/kuo.us.to\/wordpress\/wp-json\/wp\/v2\/media?parent=808"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kuo.us.to\/wordpress\/wp-json\/wp\/v2\/categories?post=808"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kuo.us.to\/wordpress\/wp-json\/wp\/v2\/tags?post=808"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}