{"id":94640,"date":"2020-05-10T21:02:34","date_gmt":"2020-05-10T13:02:34","guid":{"rendered":"http:\/\/4563.org\/?p=94640"},"modified":"2020-05-20T07:25:27","modified_gmt":"2020-05-19T23:25:27","slug":"github-%e5%bc%80%e6%ba%90%e9%a1%b9%e7%9b%ae%e6%96%b0%e9%97%bb%e7%b1%bb%e7%88%ac%e8%99%ab%ef%bc%8c%e6%87%92%e4%ba%ba%e5%bf%85%e5%a4%87%ef%bc%81","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=94640","title":{"rendered":"GitHub \u5f00\u6e90\u9879\u76ee\u65b0\u95fb\u7c7b\u722c\u866b\uff0c\u61d2\u4eba\u5fc5\u5907\uff01"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  GitHub \u5f00\u6e90\u9879\u76ee\u65b0\u95fb\u7c7b\u722c\u866b\uff0c\u61d2\u4eba\u5fc5\u5907\uff01               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zhijieju <\/span>  <span><i><\/i> 22<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>hello\uff0c\u5c0f\u4f19\u4f34\u4eec\u5927\u5bb6\u597d<\/p>\n<p>\u4eca\u5929\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u7684\u5f00\u6e90\u9879\u76ee\u662f python \u722c\u866b\u5229\u5668\uff0c\u4f7f\u7528 python \u8bed\u8a00\u7684\u5c0f\u4f19\u4f34\u4eec\u7684\u798f\u5229\u54e6\uff01\u5047\u5982\u4f60\u5728\u5de5\u4f5c\u4e2d\u63a5\u5230\u4ea7\u54c1\u5c0f\u59d0\u59d0\u7684\u9700\u6c42\uff0c\u9700\u6c42\u662f\u83b7\u53d6\u4eca\u65e5\u5934\u6761\u3001\u7f51\u6613\u65b0\u95fb\u3001\u6e38\u6c11\u661f\u7a7a\u3001 \u89c2\u5bdf\u8005\u7f51\u3001\u51e4\u51f0\u7f51\u3001\u817e\u8baf\u65b0\u95fb\u3001ReadHub \u3001\u65b0\u6d6a\u65b0\u95fb\u7b49\u6570\u767e\u4e2a\u4e2d\u6587\u65b0\u95fb\u7f51\u7ad9\u4e2d\u8f93\u51fa\u6b63\u6587\u5185\u5bb9\u3001\u6807\u9898\u3001\u4f5c\u8005\u3001\u53d1\u5e03\u65f6\u95f4\u3001\u6b63\u6587\u4e2d\u7684\u56fe\u7247\u5730\u5740\u548c\u6b63\u6587\u6240\u5728\u7684\u6807\u7b7e\u6e90\u4ee3\u7801\uff0c\u4f60\u4f1a\u600e\u4e48\u505a\uff0c\u5047\u5982\u4f60 code \u529f\u529b\u8fd8\u6ca1\u6709\u7ecf\u8fc7\u4e5d\u4e5d\u516b\u5341\u4e00\u5929\u7684\u4fee\u70bc\uff0c\u8fd8\u6ca1\u6709\u7ec3\u5230\u5143\u5a74\u671f\uff0c\u4f60\u8111\u5b50\u91cc\u5e94\u8be5\u60f3\u7684\u662f\u6211\u8981\u5199\u8fd9\u4e48\u591a\u89c4\u5219\uff0c\u53ef\u600e\u4e48\u529e\uff0c\u8981\u7d2f\u6b7b\u4eba\u5462\uff01\u8981\u662f\u6709\u4e00\u4e2a\u901a\u7528\u7684\u89c4\u5219\u5c31\u597d\u4e86\uff0ceverybady \u73b0\u5728\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u7684\u8fd9\u4e2a\u5f00\u6e90\u9879\u76ee\u5c31\u5b8c\u7f8e\u7684\u89e3\u51b3\u4e86\u8fd9\u4e2a\u95ee\u9898\uff0c\u4ed6\u6765\u4e86\uff0c\u4ed6\u6765\u4e86\uff0c\u4ed6\u5e26\u7740\u5f00\u6e90\u9879\u76eeGeneralNewsExtractor\u8d70\u6765\u4e86\u3002<\/p>\n<h3><strong>GNE \u662f\u4ec0\u4e48\uff1f<\/strong><\/h3>\n<blockquote>\n<p>GeneralNewsExtractor \uff08 GNE \uff09\u662f\u4e00\u4e2a\u901a\u7528\u65b0\u95fb\u7f51\u7ad9\u6b63\u6587\u62bd\u53d6\u6a21\u5757\uff0c\u4f1a\u8f93\u5165\u4e00\u7bc7\u65b0\u95fb\u7f51\u9875\u7684 HTML\uff0c \u8f93\u51fa\u6b63\u6587\u5185\u5bb9\u3001\u6807\u9898\u3001\u4f5c\u8005\u3001\u53d1\u5e03\u65f6\u95f4\u3001\u6b63\u6587\u4e2d\u7684\u56fe\u7247\u5730\u5740\u548c\u6b63\u6587\u6240\u5728\u7684\u6807\u7b7e\u6e90\u4ee3\u7801\u3002GNE \u5728\u63d0\u53d6\u4eca\u65e5\u5934\u6761\u3001\u65b0\u6d6a\uff0c\u817e\u8baf\u65b0\u95fb\u7b49\u6570\u767e\u4e2a\u4e2d\u6587\u65b0\u95fb\u7f51\u7ad9\u4e0a\u6548\u679c\u975e\u5e38\u51fa\u8272\uff0c\u51e0\u4e4e\u80fd\u591f\u8fbe\u5230 100%\u7684\u51c6\u786e\u7387\u3002<\/p>\n<\/blockquote>\n<p><strong>\u4f7f\u7528\u65b9\u5f0f\u4e5f\u7279\u522b\u7b80\u5355\uff1a<\/strong><\/p>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/05\/20200519_5ec46ab84535b.jpg\" alt=\"GitHub \u5f00\u6e90\u9879\u76ee\u65b0\u95fb\u7c7b\u722c\u866b\uff0c\u61d2\u4eba\u5fc5\u5907\uff01\" \/><\/p>\n<h3>\u5b89\u88c5<\/h3>\n<p><strong>\u5728\u7ebf\u4f53\u9a8c<\/strong><\/p>\n<blockquote>\n<p>\u5982\u679c\u4f60\u60f3\u5148\u4f53\u9a8c GNE \u7684\u63d0\u53d6\u6548\u679c\uff0c\u90a3\u4e48\u4f60\u53ef\u4ee5\u8bbf\u95ee: <code>http:\/\/122.51.39.219<\/code>\u3002 \u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u4f60\u53ea\u9700\u8981\u628a\u7f51\u9875\u7c98\u8d34\u5230\u6700\u4e0a\u9762\u7684\u591a\u884c\u6587\u672c\u6846\u4e2d\uff0c\u7136\u540e\u70b9 <strong>\u63d0\u53d6<\/strong> \u6309\u94ae\u5373\u53ef\u3002<\/p>\n<\/blockquote>\n<p><strong>\u5b89\u88c5 GNE<\/strong><\/p>\n<pre><code>pip install --upgrade gne <\/code><\/pre>\n<p><strong>\u4f7f\u7528 GNE<\/strong><\/p>\n<pre><code>from gne import GeneralNewsExtractor html = '''\u7ecf\u8fc7\u6e32\u67d3\u7684\u7f51\u9875 HTML \u4ee3\u7801''' extractor = GeneralNewsExtractor() result = extractor.extract(html, noise_node_list=['\/\/div[@class=\"comment-list\"]']) print(result) {\"title\": \"xxxx\", \"publish_time\": \"2020-03-21 09:00:00\", \"author\": \"yyy\", \"content\": \"zzzz\", \"images\": [\"\/xxx.jpg\", \"\/yyy.png\"]} <\/code><\/pre>\n<p><strong>\u5f53\u7136\uff0cXPath \u662f\u652f\u6301\u81ea\u5b9a\u4e49\u89c4\u5219\u7684<\/strong><\/p>\n<pre><code>from gne import GeneralNewsExtractor  extractor = GeneralNewsExtractor() html = '\u4f60\u7684\u76ee\u6807\u7f51\u9875\u6b63\u6587' result = extractor.extract(html, title_xpath='\/\/h5\/text()') print(result) <\/code><\/pre>\n<h3>\u4f7f\u7528\u6548\u679c<\/h3>\n<p><strong>\u7f51\u6613\u65b0\u95fb<\/strong> <img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/05\/20200519_5ec46abca3375.jpg\" alt=\"GitHub \u5f00\u6e90\u9879\u76ee\u65b0\u95fb\u7c7b\u722c\u866b\uff0c\u61d2\u4eba\u5fc5\u5907\uff01\" \/> <strong>\u4eca\u65e5\u5934\u6761<\/strong> <img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/05\/20200519_5ec46ac7d353f.png\" alt=\"GitHub \u5f00\u6e90\u9879\u76ee\u65b0\u95fb\u7c7b\u722c\u866b\uff0c\u61d2\u4eba\u5fc5\u5907\uff01\" \/> <strong>\u65b0\u6d6a\u65b0\u95fb<\/strong> <img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/05\/20200519_5ec46ace50f92.jpg\" alt=\"GitHub \u5f00\u6e90\u9879\u76ee\u65b0\u95fb\u7c7b\u722c\u866b\uff0c\u61d2\u4eba\u5fc5\u5907\uff01\" \/> <strong>\u51e4\u51f0\u7f51<\/strong> <img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/05\/20200519_5ec46ad7d6346.png\" alt=\"GitHub \u5f00\u6e90\u9879\u76ee\u65b0\u95fb\u7c7b\u722c\u866b\uff0c\u61d2\u4eba\u5fc5\u5907\uff01\" \/><\/p>\n<h3>API<\/h3>\n<p><strong>GNE \u7684\u51fd\u6570\u539f\u578b\u4e3a\uff1a<\/strong><\/p>\n<pre><code>class GeneralNewsExtractor:     def extract(self, html, title_xpath='', host='', author_xpath='', publish_time_xpath='', noise_node_list=None, with_body_html=False) <\/code><\/pre>\n<p><strong>\u5404\u4e2a\u53c2\u6570\u7684\u610f\u4e49\u5982\u4e0b\uff1a<\/strong><\/p>\n<ul>\n<li>html(str): \u76ee\u6807\u7f51\u7ad9\u7684\u6e90\u4ee3\u7801\u3002<\/li>\n<li>title_xpath(str): \u65b0\u95fb\u6807\u9898\u7684 XPath\uff0c\u7528\u4e8e\u5b9a\u5411\u63d0\u53d6\u6807\u9898\u3002<\/li>\n<li>host(str): \u56fe\u7247\u6240\u5728\u7684\u57df\u540d\uff0c\u4f8b\u5982 https:\/\/www.kingname.info, \u90a3\u4e48\uff0c\u5f53 GNE \u4ece\u65b0\u95fb\u7f51\u7ad9\u63d0\u53d6\u5230\u56fe\u7247\u7684\u76f8\u5bf9\u8fde\u63a5<code>\/images\/123.png<\/code>\u65f6\uff0c\u4f1a\u628a host \u62fc\u63a5\u4e0a\u53bb\uff0c\u53d8\u6210<code>https:\/\/www.kingname.info\/images\/123.png<\/code><\/li>\n<li>noise_node_list(List[str]): \u4e00\u4e2a\u5305\u542b XPath \u7684\u5217\u8868\u3002\u8fd9\u4e2a\u5217\u8868\u4e2d\u7684 XPath \u5bf9\u5e94\u7684\u6807\u7b7e\uff0c\u4f1a\u5728\u9884\u5904\u7406\u65f6\u88ab\u76f4\u63a5\u5220\u9664\u6389\uff0c\u4ece\u800c\u907f\u514d\u4ed6\u4eec\u5f71\u54cd\u65b0\u95fb\u6b63\u6587\u7684\u63d0\u53d6\u3002<\/li>\n<li>with_body_html(bool): \u9ed8\u8ba4\u4e3a False\uff0c\u6b64\u65f6\uff0c\u8fd4\u56de\u7684\u63d0\u53d6\u7ed3\u679c\u4e0d\u542b\u65b0\u95fb\u6b63\u6587\u6240\u5728\u6807\u7b7e\u7684 HTML \u6e90\u4ee3\u7801\u3002\u5f53\u628a\u5b83\u8bbe\u7f6e\u4e3a True \u65f6\uff0c\u8fd4\u56de\u7684\u7ed3\u679c\u4f1a\u5305\u542b\u5b57\u6bb5 body_html\uff0c\u5185\u5bb9\u662f\u65b0\u95fb\u6b63\u6587\u6240\u5728\u6807\u7b7e\u7684 HTML \u6e90\u4ee3\u7801\u3002<\/li>\n<li>author_xpath(str): \u6587\u7ae0\u4f5c\u8005\u7684 XPath\uff0c\u7528\u4e8e\u5b9a\u5411\u63d0\u53d6\u6587\u7ae0\u4f5c\u8005\u3002<\/li>\n<li>publish_time_xpath(str): \u6587\u7ae0\u53d1\u5e03\u65f6\u95f4\u7684 XPath\uff0c\u7528\u4e8e\u5b9a\u5411\u63d0\u53d6\u6587\u7ae0\u53d1\u5e03\u65f6\u95f4<\/li>\n<\/ul>\n<p><strong>\u5f00\u6e90\u9879\u76ee\u5730\u5740\uff1a https:\/\/github.com\/kingname\/GeneralNewsExtractor<\/strong><\/p>\n<p>\u6709\u5174\u8da3\u7684\u5c0f\u4f19\u4f34\u53ef\u4ee5\u4e0b\u8f7d\u5c1d\u8bd5\u5e94\u7528\u4e00\u4e0b\uff0c\u5982\u679c\u5728\u4f7f\u7528\u671f\u95f4\u9047\u5230\u95ee\u9898\u8bf7\u5728\u4e0b\u65b9\u7559\u8a00\u6216\u79c1\u4fe1\u6211\uff01<\/p>\n<p>\u4eca\u5929\u7684\u63a8\u8350\u4e0d\u77e5\u9053\u5927\u5bb6\u559c\u6b22\u5417\uff1f\u5982\u679c\u4f60\u4eec\u559c\u6b22\u8bdd\uff0c\u8bf7\u5728\u6587\u7ae0\u5e95\u90e8\u7559\u8a00\u548c\u70b9\u8d5e\uff0c\u4ee5\u8868\u793a\u5bf9\u6211\u7684\u652f\u6301\uff0c\u4f60\u4eec\u7684\u7559\u8a00\uff0c\u70b9\u8d5e\u548c\u8f6c\u53d1\u5173\u6ce8\u662f\u6211\u6301\u7eed\u66f4\u65b0\u7684\u52a8\u529b\u54e6\uff01<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2020\/05\/20200320211950783.jpgpic_center-1.png\" alt=\"GitHub \u5f00\u6e90\u9879\u76ee\u65b0\u95fb\u7c7b\u722c\u866b\uff0c\u61d2\u4eba\u5fc5\u5907\uff01\" \/><\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>0<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>GitHub \u5f00\u6e90\u9879\u76ee\u65b0\u95fb\u7c7b\u722c\u866b\uff0c&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\/94640"}],"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=94640"}],"version-history":[{"count":1,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/94640\/revisions"}],"predecessor-version":[{"id":94642,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/94640\/revisions\/94642"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=94640"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=94640"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=94640"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}