{"id":1026,"date":"2022-11-14T09:16:54","date_gmt":"2022-11-14T01:16:54","guid":{"rendered":"https:\/\/blog.langsasec.cn\/?p=1026"},"modified":"2022-11-14T09:17:43","modified_gmt":"2022-11-14T01:17:43","slug":"pyrmpc","status":"publish","type":"post","link":"https:\/\/blog.langsasec.cn\/index.php\/2022\/11\/14\/pyrmpc\/","title":{"rendered":"\u3010Python \u201c\u5077\u61d2\u201d\u5165\u95e8\u4e13\u680f\u3011\u548cweb\u804a\u5929"},"content":{"rendered":"<h2><span class=\"ez-toc-section\" id=\"%e5%89%8d%e8%a8%80\"><\/span>\u524d\u8a00<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u6211\u4eec\u5f88\u591a\u65f6\u5019\u60f3\u8981\u548cweb\u7ad9\u70b9\u8fdb\u884c\u4ea4\u4e92\uff0c\u548c\u4ed6\u804a\u804a\u5929\uff0c\u6d4f\u89c8\u6d4f\u89c8\u7ad9\u70b9\uff0c\u627e\u4ed6\u8981\u70b9\u4e1c\u897f\u662f\u5427\u3002\u7ecf\u5e38\u542c\u5230\u7684\u722c\u866b\u5c31\u662f\u4ece\u7ad9\u70b9\u4e0a\u6293\u53d6\u81ea\u5df1\u60f3\u8981\u7684\u4e1c\u897f\u3002\u672c\u671f\u7684\u5185\u5bb9\u5c31\u662f\u56f4\u7ed5\u600e\u4e48\u7528\u7f16\u7a0b\u7684\u65b9\u5f0f\u6765\u5411\u670d\u52a1\u5668\u53d1\u8d77\u8bf7\u6c42\uff0c\u548c\u4ed6\u804a\u5929\u3002<\/p>\n<p>\u5176\u5b9e\uff0c\u6211\u4eec\u7528\u6d4f\u89c8\u5668\u53bb\u8bbf\u95ee\u4e00\u4e2a\u7f51\u7ad9\u7684\u65f6\u5019\u3002\u6211\u4eec\u662f\u901a\u8fc7\u6d4f\u89c8\u5668\u53bb\u53d1\u9001\u4e00\u4e32\u8bf7\u6570\u636e\u5411\u670d\u52a1\u5668\u8bf7\u6c42\uff0c\u7136\u540e\u63a5\u53d7\u670d\u52a1\u5668\u7684\u53cd\u9988\u3002\u800c\u7528\u7f16\u7a0b\u7684\u65b9\u5f0f\uff0c\u5c31\u662f\u6a21\u62df\u6d4f\u89c8\u5668\u6784\u9020\u6570\u636e\u5411\u670d\u52a1\u5668\u53d1\u9001\u8bf7\u6c42\u548c\u63a5\u53d7\u4fe1\u606f\u7684\u8fc7\u7a0b\uff0c\u63a5\u4e0b\u6765\u5c31\u8bb2\u8bb2\u600e\u4e48\u901a\u8fc7Python\u7f16\u7a0b\u6765\u6784\u9020\u3001\u8bf7\u6c42\u3001\u63a5\u6536\u8fd9\u4e9b\u6570\u636e\u3002<\/p>\n<h2><span class=\"ez-toc-section\" id=\"urllib%e3%80%81urllib2-%e3%80%81requests%e6%a8%a1%e5%9d%97%e4%bb%8b%e7%bb%8d\"><\/span>urllib\u3001urllib2 \u3001requests\u6a21\u5757\u4ecb\u7ecd<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u5e38\u89c1\u7684\u4e0eweb\u7a0b\u5e8f\u8fdb\u884c\u4ea4\u4e92\u7684python\u6a21\u5757\u4e3a<strong><em>\\<\/em>u*****<\/strong>*rllib*<strong>**<\/strong>*\u3001*<strong>**<\/strong>*urllib2*<strong>**<\/strong>*\u548c*<strong>**<\/strong>*requests****\uff0curllib\u548curllib2\u7684\u529f\u80fd\u76f8\u4f3c\uff0c\u4f46\u4e5f\u5b58\u5728\u4e00\u5b9a\u7684\u5f02\u540c\uff0c\u5982\uff1a\u90fd\u662f\u53ef\u4ee5\u901a\u8fc7urlopen()\u8bf7\u6c42\u4e00\u4e2a\u7f51\u7ad9\uff0c\u4f46\u662furllib\u5b58\u5728urlretrieve()\u65b9\u6cd5\uff0c\u53ef\u7528\u4e8e\u4e0b\u8f7d\u6587\u4ef6,urllib2\u5b58\u5728Requests\u6a21\u5757\u64cd\u4f5c\u66f4\u7b80\u4fbf\u3002PS\uff1apython 3\u5c06urllib2\u96c6\u6210\u5230\u4e86urllib\u91cc\u9762\uff0c\u5373\u6ca1\u6709urllib2\u6a21\u5757\u3002<\/p>\n<p>\u90a3requests\u6a21\u5757\u662f\u4ec0\u4e48\uff1f\u662f\u96c6\u6210\u4e86\u4ee5\u4e0a\u4e24\u4e2a\u6a21\u5757\u7684\u529f\u80fd\uff0c\u80fd\u591f\u5f88\u65b9\u4fbf\u7684\u4e0eweb\u7a0b\u5e8f\u8fdb\u884c\u4ea4\u4e92\u3002\u5f53\u4f60\u7528\u4e86requests\u6a21\u5757\u7684\u65f6\u5019\uff0c\u5c31\u4e0d\u4f1a\u60f3\u8981\u518d\u7528urllib\u548curllib2\u4e86\u3002\u4ee5\u4e0b\u4e3b\u8981\u4ecb\u7ecdrequests\u6a21\u5757\uff0c\u60f3\u4e86\u89e3urllib\u548curllib2\u6a21\u5757\u53ef\u81ea\u884c\u4e86\u89e3\u3002<\/p>\n<p><strong><em>\\<\/em>requests*****<\/strong>*\u6a21\u5757*<strong>**<\/strong>*\u4ecb\u7ecd****<\/p>\n<p>1\u3001\u5b89\u88c5\uff1apip install requests<\/p>\n<p>2\u3001\u53d1\u9001\u7f51\u7edc\u8bf7\u6c42<\/p>\n<p>r = requests.get(url) \u83b7\u53d6html\u7684\u4e3b\u8981\u65b9\u6cd5<\/p>\n<p>r = requests.post(url) \u5411html\u7f51\u9875\u63d0\u4ea4post\u8bf7\u6c42\u7684\u65b9\u6cd5<\/p>\n<p>r = requests.put(url) \u5411html\u7f51\u9875\u63d0\u4ea4put\u8bf7\u6c42\u7684\u65b9\u6cd5<\/p>\n<p>r = requests.delete(url) \u5411html\u63d0\u4ea4\u5220\u9664\u8bf7\u6c42<\/p>\n<p>r = requests.head(url) \u83b7\u53d6html\u5934\u90e8\u4fe1\u606f\u7684\u4e3b\u8981\u65b9\u6cd5<\/p>\n<p>r = requests.options(url)<\/p>\n<p>3\u3001\u4e3aurl\u4f20\u9012\u53c2\u6570<\/p>\n<p>payload={'key1':'value1','key2':'value2'}<\/p>\n<p>r=request.get(url,params=payload)<\/p>\n<p>4\u3001\u54cd\u5e94\u5185\u5bb9<\/p>\n<p>r.text<\/p>\n<p>5\u3001\u4e8c\u8fdb\u5236\u54cd\u5e94\u5185\u5bb9<\/p>\n<p>r.content<\/p>\n<p>6\u3001\u5b9a\u5236\u8bf7\u6c42\u5934<\/p>\n<p>headers=''<\/p>\n<p>r.request.get(url,headers=headers)<\/p>\n<p>7\u3001\u52a0\u5165cookies<\/p>\n<p>cookies=''<\/p>\n<p>r.request.get(url,cookies=cookies)<\/p>\n<p>8\u3001post\u8bf7\u6c42\u52a0\u5165\u53c2\u6570<\/p>\n<p>payload={'key1':'value1','key2':'value2'}<\/p>\n<p>r=request.post(url,data=payload)<\/p>\n<p>9\u3001\u54cd\u5e94\u72b6\u6001\u7801<\/p>\n<p>r.status_code -&gt;\u5982\u901a\u8fc7\u8fd9\u4e2a\u72b6\u6001\u7801\u8fdb\u884c\u76ee\u5f55\u626b\u63cf<\/p>\n<p>10\u3001\u8fd4\u56de\u54cd\u5e94\u5934<\/p>\n<p>r.headers<\/p>\n<p>11\u3001\u8fd4\u56decookies<\/p>\n<p>r.cookies<\/p>\n<p>12\u3001\u8d85\u65f6<\/p>\n<p>requests.get(url,timeout=0.0001)<\/p>\n<p>13\u3001\u9519\u8bef\u548c\u5f02\u5e38<\/p>\n<p>\u9047\u5230\u7f51\u7edc\u95ee\u9898\uff1aConnectionError\u5f02\u5e38<\/p>\n<p>\u65e0\u6548HTTP\u54cd\u5e94\uff1aHTTPError\u5f02\u5e38<\/p>\n<p>\u8bf7\u6c42\u8d85\u65f6\uff1aTimeout\u5f02\u5e38<\/p>\n<p>\u4e0a\u9762\u4ecb\u7ecd\u4e86\u90a3\u4e48\u591a\uff0c\u770b\u8d77\u6765\u5f88\u590d\u6742\uff0c\u90a3\u4e48\u6211\u4eec\u6700\u57fa\u7840\u7684\u8fd8\u662f\u8bf4\uff0c\u6784\u9020\u3001\u8bf7\u6c42\u3001\u63a5\u6536\u8fd9\u4e9b\u6570\u636e\u3002\u7528\u6cd5\u5982\u4e0b\uff1a<\/p>\n<p>import requests #\u5bfc\u5165Python\u6a21\u5757<\/p>\n<p>url='<a href=\"http:\/\/www.baidu.com\">http:\/\/www.baidu.com<\/a>' #\u8981\u8bf7\u6c42\u7684\u7f51\u7ad9<\/p>\n<p>re = requests.get(url) #\u8bf7\u6c42\u7f51\u7ad9<\/p>\n<p>result = re.text  #\u54cd\u5e94\u7684\u5185\u5bb9<\/p>\n<p>print(result) #\u6253\u5370\u54cd\u5e94\u7ed3\u679c<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/i0.hdslb.com\/bfs\/album\/d6230f8ac725ac1a899cd35ca0c878e825f3e2f1.jpg\" alt=\"img\" title=\"\u3010Python \u201c\u5077\u61d2\u201d\u5165\u95e8\u4e13\u680f\u3011\u548cweb\u804a\u5929\u63d2\u56fe\" \/> <\/p>\n<p>\u7136\u540e\u518d\u7528\u6211\u4eec\u4e0a\u671f\u5185\u5bb9\u8bb2\u5230\u7684\u6b63\u5219\u5339\u914d\u5c31\u53ef\u4ee5\u6293\u53d6\u6211\u4eec\u60f3\u8981\u7684\u5185\u5bb9\u3002<\/p>\n<p>\u90a3\u6709\u670b\u53cb\u53c8\u8981\u8bf4\u4e86\uff0c\u6211\u6293\u5230\u7684\u600e\u4e48\u662f&lt;!DOCTYPE html&gt;\u4ec0\u4e48\u4ec0\u4e48\u7684\u4e1c\u897f\u5462\uff01\u90a3\u662f\u56e0\u4e3a\u6211\u4eec\u770b\u5230\u7684\u54cd\u5e94\u5185\u5bb9\u662f\u7ad9\u70b9\u7684\u6e90\u7801\uff0c\u4f60\u53ef\u4ee5\u7528\u53f3\u952e\u67e5\u770b\u6e90\u7801\u7684\u65b9\u5f0f\uff0c\u67e5\u770b\u6e90\u7801\u7684\u5185\u5bb9\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/i0.hdslb.com\/bfs\/album\/7dbb46d1ff03b0f5eb54f30cbc749877d19232bc.jpg\" alt=\"img\" title=\"\u3010Python \u201c\u5077\u61d2\u201d\u5165\u95e8\u4e13\u680f\u3011\u548cweb\u804a\u5929\u63d2\u56fe1\" \/> <\/p>\n<h2><span class=\"ez-toc-section\" id=\"%e7%88%ac%e8%99%ab\"><\/span>\u722c\u866b<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u6309\u7167\u8bbe\u5b9a\u7684\u89c4\u5219\uff0c\u81ea\u52a8\u7684\u53bb\u722c\u53d6\u4e07\u7ef4\u7f51\u4fe1\u606f\u7684\u7a0b\u5e8f\u6216\u811a\u672c\u3002<\/p>\n<p>\u4f18\u70b9\uff1a\uff08\u6279\u91cf\u3001\u81ea\u52a8\u5316\uff09=\uff08\u7701\u65f6\u3001\u7701\u529b\uff09<\/p>\n<p>\u5b89\u5168\u5e94\u7528\u89d2\u5ea6\uff1a\u7528\u4e8e\u76ee\u5f55\u626b\u63cf\u3001\u641c\u7d22\u6d4b\u8bd5\u9875\u9762\u3001\u641c\u7d22\u7ba1\u7406\u5458\u767b\u5f55\u754c\u9762\u3001\u5f00\u53d1web\u7684\u6f0f\u6d1e\u626b\u63cf\u3002<\/p>\n<h2><span class=\"ez-toc-section\" id=\"%e5%ae%9e%e6%88%98%ef%bc%9a%e5%88%a9%e7%94%a8python%e5%bc%80%e5%8f%91%e4%b8%80%e4%b8%aa%e7%88%ac%e8%99%ab\"><\/span>\u5b9e\u6218\uff1a\u5229\u7528python\u5f00\u53d1\u4e00\u4e2a\u722c\u866b<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u5c0f\u7f16\u53d1\u73b0\u8fd9\u6837\u4e00\u4e2a\u7f51\u7ad9\uff1a<a href=\"https:\/\/www.xuexila.com\/,\u5982\u4e0b\u56fe\u6240\u793a\uff0c\u56fe\u4e2d\u6709\u5757\u4eca\u65e5\u63a8\u8350\u7684\u6a21\u5757\uff0c\u6bcf\u5929\u91cc\u9762\u6709\u63a8\u8350\u7684\u6587\u7ae0\u3002\u90a3\u5c0f\u7f16\u662f\u4e2a\u6bd4\u8f83\u61d2\u7684\u4eba\uff0c\u800c\u4e14\u4e0d\u662f\u6bcf\u4e00\u7bc7\u6587\u7ae0\u90fd\u662f\u5c0f\u6807\u60f3\u770b\u7684\u6587\u7ae0\uff0c\u6240\u4ee5\u5c31\u60f3\u7740\u7528\u722c\u866b\u7684\u65b9\u5f0f\uff0c\u722c\u4e0b\u4ed6\u63a8\u8350\u7684\u6587\u7ae0\u7684\u540d\u79f0\u548c\u6587\u7ae0\u7684\u94fe\u63a5\uff0c\u8fd9\u6837\u5c0f\u7f16\u5c31\u4e0d\u7528\u53bb\u6253\u5f00\u7f51\u7ad9\u53bb\u770b\u63a8\u8350\u4e86\u4ec0\u4e48\u4e86\">https:\/\/www.xuexila.com\/,\u5982\u4e0b\u56fe\u6240\u793a\uff0c\u56fe\u4e2d\u6709\u5757\u4eca\u65e5\u63a8\u8350\u7684\u6a21\u5757\uff0c\u6bcf\u5929\u91cc\u9762\u6709\u63a8\u8350\u7684\u6587\u7ae0\u3002\u90a3\u5c0f\u7f16\u662f\u4e2a\u6bd4\u8f83\u61d2\u7684\u4eba\uff0c\u800c\u4e14\u4e0d\u662f\u6bcf\u4e00\u7bc7\u6587\u7ae0\u90fd\u662f\u5c0f\u6807\u60f3\u770b\u7684\u6587\u7ae0\uff0c\u6240\u4ee5\u5c31\u60f3\u7740\u7528\u722c\u866b\u7684\u65b9\u5f0f\uff0c\u722c\u4e0b\u4ed6\u63a8\u8350\u7684\u6587\u7ae0\u7684\u540d\u79f0\u548c\u6587\u7ae0\u7684\u94fe\u63a5\uff0c\u8fd9\u6837\u5c0f\u7f16\u5c31\u4e0d\u7528\u53bb\u6253\u5f00\u7f51\u7ad9\u53bb\u770b\u63a8\u8350\u4e86\u4ec0\u4e48\u4e86<\/a>\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/i0.hdslb.com\/bfs\/album\/c7553c4f2706671d12058a03c2d39d3e193169ac.jpg\" alt=\"img\" title=\"\u3010Python \u201c\u5077\u61d2\u201d\u5165\u95e8\u4e13\u680f\u3011\u548cweb\u804a\u5929\u63d2\u56fe2\" \/> <\/p>\n<p>\u9488\u5bf9\u8fd9\u4e2a\u9700\u6c42\uff0c\u6211\u4eec\u5199\u4e86\u4e2a\u722c\u866b\uff0c\u5148\u722c\u53d6\u9875\u9762\u7684\u4fe1\u606f\uff0c\u518d\u901a\u8fc7\u4e0a\u4e00\u7bc7\u6587\u7ae0\u5b66\u4e60\u7684\u6b63\u5219\u5339\u914d\u53bb\u5339\u914d\u91cc\u9762\u7684\u5185\u5bb9\u3002<\/p>\n<p>\u6548\u679c\u5982\u4e0b\uff1a<\/p>\n<p>\u7b2c\u4e00\u6b65\uff0c\u5148\u5c1d\u8bd5\u722c\u53d6\u9875\u9762\u7684\u4fe1\u606f\uff0c\u53d1\u73b0\u6211\u4eec\u722c\u53d6\u7684\u4e2d\u6587\u90fd\u662f\u4e71\u7801\u7684<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/i0.hdslb.com\/bfs\/album\/bfc86ad0c7a84aacde3441d9bd3e0814e600ed21.jpg\" alt=\"img\" title=\"\u3010Python \u201c\u5077\u61d2\u201d\u5165\u95e8\u4e13\u680f\u3011\u548cweb\u804a\u5929\u63d2\u56fe3\" \/> <\/p>\n<p>\u6211\u4eec\u52a0\u5165r.encoding ='utf-8' \u8c03\u6574\u7f16\u7801\u683c\u5f0f\uff0c\u5c31\u53ef\u4ee5\u5f97\u5230\u6b63\u5e38\u7684\u60c5\u51b5<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/i0.hdslb.com\/bfs\/album\/ba2d39d538bd03526a6b2cb1fbcda02da3138431.jpg\" alt=\"img\" title=\"\u3010Python \u201c\u5077\u61d2\u201d\u5165\u95e8\u4e13\u680f\u3011\u548cweb\u804a\u5929\u63d2\u56fe4\" \/> <\/p>\n<p>\u7b2c\u4e8c\u6b65\uff0c\u6211\u4eec\u5148\u5c1d\u8bd5\u722c\u53d6\u6587\u7ae0\u540d\u79f0\uff0c\u6211\u4eec\u5229\u7528\u67e5\u770b\u6e90\u7801\u7684\u529f\u80fd\u6216\u8005\u6211\u4eec\u722c\u4e0b\u6765\u7684\u6e90\u7801\u53bb\u5206\u6790\u6211\u4eec\u8981\u63d0\u53d6\u7684\u5185\u5bb9\u524d\u540e\u7684\u7279\u5f81\uff0c\u53ef\u4ee5\u770b\u5230\u6211\u4eec\u8981\u63d0\u53d6\u7684\u4eca\u65e5\u63a8\u8350\u6587\u7ae0\u540d\u5b57\u7684\u524d\u9762\u90fd\u662ftitle=\u201d<\/p>\n<p>\u540e\u9762\u662f&quot; class=&quot;lb_1 chao&quot;&gt;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/i0.hdslb.com\/bfs\/album\/018d6b5099f76af59cf064e95f9522101e797470.jpg\" alt=\"img\" title=\"\u3010Python \u201c\u5077\u61d2\u201d\u5165\u95e8\u4e13\u680f\u3011\u548cweb\u804a\u5929\u63d2\u56fe5\" \/> <\/p>\n<p>\u90a3\u4e48\u6211\u4eec\u53ef\u4ee5\u4e66\u5199\u6b63\u5219\u5339\u914d\uff1ar'title=&quot;(.*?)&quot; class=&quot;lb_1 chao&quot;&gt;'<\/p>\n<p>\u5c1d\u8bd5\u8fdb\u884c\u5339\u914d\uff0c\u53ef\u4ee5\u770b\u5230\uff0c\u6211\u4eec\u722c\u53d6\u5230\u4e86\u6587\u7ae0\u540d\u79f0\uff0c\u9a8c\u8bc1\u4e00\u4e0b\u53d1\u73b0\u548c\u622a\u56fe\u91cc\u9762\u7684\u5185\u5bb9\u662f\u4e00\u81f4\u7684<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/i0.hdslb.com\/bfs\/album\/5103268df8c638e6e8ced1d40926653427b8b82c.jpg\" alt=\"img\" title=\"\u3010Python \u201c\u5077\u61d2\u201d\u5165\u95e8\u4e13\u680f\u3011\u548cweb\u804a\u5929\u63d2\u56fe6\" \/> <\/p>\n<p>\u7b2c\u4e09\u6b65\uff1a\u7528\u540c\u6837\u7684\u65b9\u6cd5\u53bb\u5339\u914d\u6587\u7ae0\u5bf9\u5e94\u7684\u94fe\u63a5\uff0c\u7b80\u5355\u7684\u8c03\u6574\u4e00\u4e0b\uff0c\u6211\u4eec\u5c31\u5f97\u5230\u5982\u4e0b\u7684\u7ed3\u679c<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/i0.hdslb.com\/bfs\/album\/6e9574690f6c6de1d90cc70ec898c3fce301fdd3.jpg\" alt=\"img\" title=\"\u3010Python \u201c\u5077\u61d2\u201d\u5165\u95e8\u4e13\u680f\u3011\u548cweb\u804a\u5929\u63d2\u56fe7\" \/> <\/p>\n<p>\u5c06\u94fe\u63a5\u62ff\u51fa\u6765\u6d4b\u8bd5\u4e00\u4e0b\uff0c\u53d1\u73b0\u65e0\u8bef\uff0c\u722c\u53d6\u6210\u529f\uff0c\u76ee\u6807\u8fbe\u6210\uff08\u6bcf\u5929\u8dd1\u4e00\u4e0b\uff0c\u5c31\u53ef\u4ee5\u770b\u5230\u8be5\u7ad9\u70b9\u7684\u6bcf\u65e5\u63a8\u8350\u4fe1\u606f\uff09\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/i0.hdslb.com\/bfs\/album\/0becf00e22396bdc4b66fc5b17781995b4e4842a.jpg\" alt=\"img\" title=\"\u3010Python \u201c\u5077\u61d2\u201d\u5165\u95e8\u4e13\u680f\u3011\u548cweb\u804a\u5929\u63d2\u56fe8\" \/> <\/p>\n<p><strong><em>*\u516c\u4f17\u53f7\u56de\u590d\u201c\u548cweb\u804a\u5929\u201d\u83b7\u53d6\u722c\u866b\u6e90\u7801\u3002*<\/em><\/strong><\/p>\n<p>\u5168\u90e8\u4ee3\u7801\u5982\u4e0b\uff1a\uff08#\u53f7\u6ce8\u91ca\u7684\u5185\u5bb9\uff0c\u9664\u4e86\u7b2c\u4e00\u6761\uff0c\u5176\u4ed6\u7684\u5747\u4e3a\u5f00\u53d1\u8fc7\u7a0b\u4e2d\u7684\u6d4b\u8bd5\u8bed\u53e5\uff0c\u53ef\u4ee5\u5220\u9664\u3002\u5220\u9664\u4e4b\u540e\u4f60\u4f1a\u53d1\u73b0\uff0c\u6211\u4eec\u5b9e\u73b0\u8fd9\u4e2a\u529f\u80fd\u6240\u9700\u4ee3\u7801\u91cf\u5f88\u5c11\u3002\uff09<\/p>\n<p># encoding:utf-8<\/p>\n<p>import requests<\/p>\n<p>import re<\/p>\n<p>url = '<a href=\"https:\/\/www.xuexila.com\/\">https:\/\/www.xuexila.com\/<\/a>'<\/p>\n<p>r = requests.get(url)<\/p>\n<p>r.encoding ='utf-8'<\/p>\n<p># print(r.text)<\/p>\n<p>pattern = r'title=&quot;(.*?)&quot; class=&quot;lb_1 chao&quot;&gt;'<\/p>\n<p>title = re.findall(pattern,r.text)<\/p>\n<p># print(title)<\/p>\n<p># for i in title:<\/p>\n<p>#   print(i)<\/p>\n<p>pattern2 = r'<a href=\"\/\/(.*?)\" target=\"_blank\" rel=\"noopener\">'<\/p>\n<p>links = re.findall(pattern2,r.text)<\/p>\n<p># print(links)<\/p>\n<p># for link in links:<\/p>\n<p>#   print(link)<\/p>\n<p>for i in range(0,len(links)):<\/p>\n<p>print(title[i]+'   '+links[i])<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00 \u6211\u4eec\u5f88\u591a\u65f6\u5019\u60f3\u8981\u548cweb\u7ad9\u70b9\u8fdb\u884c\u4ea4\u4e92\uff0c\u548c\u4ed6\u804a\u804a\u5929\uff0c\u6d4f\u89c8\u6d4f\u89c8\u7ad9\u70b9\uff0c\u627e\u4ed6\u8981\u70b9\u4e1c\u897f\u662f\u5427\u3002\u7ecf\u5e38\u542c\u5230\u7684\u722c\u866b\u5c31\u662f\u4ece\u7ad9 [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[37],"tags":[],"class_list":["post-1026","post","type-post","status-publish","format-standard","hentry","category-aqkf"],"_links":{"self":[{"href":"https:\/\/blog.langsasec.cn\/index.php\/wp-json\/wp\/v2\/posts\/1026","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.langsasec.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.langsasec.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.langsasec.cn\/index.php\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.langsasec.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1026"}],"version-history":[{"count":2,"href":"https:\/\/blog.langsasec.cn\/index.php\/wp-json\/wp\/v2\/posts\/1026\/revisions"}],"predecessor-version":[{"id":1028,"href":"https:\/\/blog.langsasec.cn\/index.php\/wp-json\/wp\/v2\/posts\/1026\/revisions\/1028"}],"wp:attachment":[{"href":"https:\/\/blog.langsasec.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1026"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.langsasec.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1026"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.langsasec.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1026"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}