{"id":67623,"date":"2020-04-17T17:15:12","date_gmt":"2020-04-17T09:15:12","guid":{"rendered":"http:\/\/4563.org\/?p=67623"},"modified":"2020-04-17T17:15:12","modified_gmt":"2020-04-17T09:15:12","slug":"%e9%9a%94%e5%a3%81%e7%9c%8b%e5%88%b0%e7%9a%84%e7%88%ac%e8%99%ab%e4%b8%8b%e5%b0%8f%e8%af%b4python","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=67623","title":{"rendered":"\u9694\u58c1\u770b\u5230\u7684\u722c\u866b\u4e0b\u5c0f\u8bf4[Python]"},"content":{"rendered":"\n<p>  \t\t\t\t\t<strong>hdwan.net<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3>\u9694\u58c1\u770b\u5230\u7684\u722c\u866b\u4e0b\u5c0f\u8bf4[Python]<\/h3>\n<p>  \t\timport requests&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;#\u5bfc\u5165HTTP\u8bf7\u6c42\u5e93<br \/>  from pyquery import PyQuery&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;#PyQuery\uff0c\u539f\u751fcss\u9009\u62e9\u5668<\/p>\n<p>  &#8221;&#8217;\u83b7\u53d6\u5355\u7ae0\u8282\u5185\u5bb9&#8221;&#8217;<br \/>  def get_one_chapter(chapter_url = None, name = None):<br \/>  &nbsp; &nbsp; response = requests.get(url = chapter_url)<br \/>  &nbsp; &nbsp; doc = PyQuery(response.text)<br \/>  &nbsp; &nbsp; title = doc(&quot;h1&quot;).text()&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; #\u201ch1\u201d\u5404\u7f51\u7ad9\u6807\u7b7e\u4e0d\u5c3d\u76f8\u540c\uff0c\u8bf7\u81ea\u884c\u5206\u6790\u7f51\u7ad9\u6e90\u7801\u914d\u7f6e<br \/>  &nbsp; &nbsp; content = doc(&quot;#content&quot;).text()&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;#\u201c#content\u201d\u5404\u7f51\u7ad9\u5c0f\u8bf4\u5185\u5bb9\u5173\u952e\u8bcd\uff0c\u8bf7\u81ea\u884c\u5206\u6790\u7f51\u7ad9\u6e90\u7801\u914d\u7f6e<br \/>  &nbsp; &nbsp; print(title,content)<br \/>  &nbsp; &nbsp; with open(file = name + &quot;.txt&quot;, mode = &quot;a+&quot;, encoding = &quot;utf-8&quot;) as f:<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;f.write(title + &quot;nn&quot; + content)<\/p>\n<p>  &#8221;&#8217;\u89e3\u6790\u4e00\u672c\u4e66\u6240\u6709\u7ae0\u8282\u7684url\u548c\u4e66\u540d&#8221;<br \/>  def get_index(book_url):<br \/>  &nbsp; &nbsp; index_url = book_url<br \/>  &nbsp; &nbsp; text = requests.get(url = index_url).text<br \/>  &nbsp; &nbsp; doc = PyQuery(text)<br \/>  &nbsp; &nbsp; links = doc(&#8216;#list a&#8217;)&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;#links \u83b7\u53d6\u6240\u6709\u94fe\u63a5\u6807\u7b7e<br \/>  &nbsp; &nbsp; name = doc(&#8216;h1&#8217;).text()<br \/>  &nbsp; &nbsp; for link in list(links.items()):&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; #\u4e00\u822c\u76ee\u5f55\u7f51\u9875\u90fd\u4f1a\u6709\u9650\u663e\u793a\u6700\u65b0\u66f4\u65b0\u7ae0\u8282\uff0c\u66f4\u5177\u5b9e\u9645\u60c5\u51b5\u8df3\u8fc7\u7ae0\u8282<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;chapter_url = &#8216;http:\/\/www.XXXXXX&#8217; + link.attr.href&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;#\u9632\u6b62\u6709\u4eba\u8bf4\u6211\u6253\u5e7f\u544a\uff0c\u7f51\u5740\u81ea\u5df1\u914d\u7f6e<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;get_one_chapter(chapter_url = chapter_url, name = name)<\/p>\n<p>  &#8221;&#8217;\u89e3\u6790\u5168\u7ad9\u4e66\u7c4durl&#8221;&#8217;<br \/>  def get_all_book_url():<br \/>  &nbsp; &nbsp; all_book_url = &quot;http:\/\/www.XXXXXX&quot;<br \/>  &nbsp; &nbsp; response = requests.get(url = all_book_url).text<br \/>  &nbsp; &nbsp; doc = PyQuery(response)<br \/>  &nbsp; &nbsp; links = doc(&#8216;#main a&#8217;)<br \/>  &nbsp; &nbsp; for link in list(links.items()):<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;book_url = &#8216;http:\/\/www.XXXXXX&#8217; + link.attr.href<br \/>  &nbsp; &nbsp;&nbsp; &nbsp;get_index(book_url = book_url)<\/p>\n<p>  get_all_book_url()<\/p>\n<p>  https:\/\/www.vxotu.com\/u\/20200416\/1524233.png\t\t\t\t<\/p>\n<p>  \t\t\t\t\t<strong>tir<\/strong>  \t\t\t\t\u5927\u4f6c\u6709\u8bdd\u8bf4 : \t<\/p>\n<h3><\/h3>\n<p>  \t\t\u770b\u8d77\u6765\u4e0d\u9519\uff0c\u4f46\u662f\u73b0\u5728\u4e0d\u9700\u8981\u722c\uff0c\u6709\u73b0\u6210\u7684\u89c4\u5219\t\t\t  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>hdwan.net \u5927\u4f6c\u6709\u8bdd\u8bf4 :&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\/67623"}],"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=67623"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/67623\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=67623"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=67623"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=67623"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}