{"id":277400,"date":"2021-01-13T17:43:11","date_gmt":"2021-01-13T09:43:11","guid":{"rendered":"http:\/\/4563.org\/?p=277400"},"modified":"2021-01-13T17:43:11","modified_gmt":"2021-01-13T09:43:11","slug":"%e5%a4%9a%e4%b8%aa-scrapy-%e7%88%ac%e8%99%ab%e5%90%af%e5%8a%a8%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=277400","title":{"rendered":"\u591a\u4e2a scrapy \u722c\u866b\u542f\u52a8\u95ee\u9898"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u591a\u4e2a scrapy \u722c\u866b\u542f\u52a8\u95ee\u9898               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Luzaiv7 <\/span>  <span><i><\/i> 1<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u6709\u633a\u591a scarpy \u7684\u722c\u866b\uff0c\u53d7\u9650\u4e8e\u4ee3\u7406\u6570\u91cf\uff0c\u6ca1\u6cd5\u4e00\u6b21\u6027\u5168\u90e8\u542f\u52a8\u3002\u4e8e\u662f\u60f3\u627e\u5230\u4e00\u4e2a\u7c7b\u4f3c\u961f\u5217\uff0c\u53d6\u54ea\u4e2a\u722c\u54ea\u4e2a\u7684\u65b9\u6cd5\u3002 \u76ee\u524d\u8bd5\u8fc7 \u8fdb\u7a0b\u6c60\u3001scrapy \u63a5\u53e3 \u90fd\u4e0d\u662f\u5f88\u7406\u6027 \u8fdb\u7a0b\u6c60\u7684\u95ee\u9898:<\/p>\n<blockquote>\n<p>\u6bcf\u4e2a\u8fdb\u7a0b\u6d88\u8d39\u5b8c\u7b2c\u4e00\u4e2a\u722c\u866b\uff0c\u8fdb\u7a0b\u5c31\u4f1a\u5173\u95ed<\/p>\n<\/blockquote>\n<p>scrapy \u63a5\u53e3\u7684\u95ee\u9898:<\/p>\n<blockquote>\n<p>\u5fc5\u987b\u6309\u987a\u5e8f\u722c\uff0c\u5047\u5982\u5176\u4ed6\u8fdb\u7a0b\u8dd1\u5b8c\uff0c\u5269\u4e0b\u672a\u8dd1\u5b8c\u7684\u722c\u866b\u8fd8\u662f\u5f97\u4e00\u4e2a\u4e2a\u6309\u987a\u5e8f\u8dd1\uff0c\u6d6a\u8d39\u65f6\u95f4<\/p>\n<\/blockquote>\n<p>\u4ee5\u4e0b\u662f\u8fdb\u7a0b\u6c60\u7684\u4ee3\u7801<\/p>\n<pre><code>from scrapy.crawler import CrawlerProcess from multiprocessing import Pool  def _crawl_main_program(spider, settings):  # spider: \u722c\u866b     process = CrawlerProcess(settings)     process.crawl(spider)     process.start()   def _crawl_running(crawl_map: dict, settings: dict, max_processes=5):  # crawl_map: scrapy \u722c\u866b\u6620\u5c04\u8868     if not crawl_map:         raise CrawlError()     executor = Pool(processes=max_processes)     for domain, spider in crawl_map.items():         executor.apply_async(_crawl_main_program, (spider, settings))     executor.close()     executor.join()          def core_website_crawl():     _crawl_running(crawl_map=core_spider_domain_map,      settings=core_website_crawl_settings)           if __name__ == '__main__':     core_website_crawl() <\/code><\/pre>\n<p>\u60f3\u627e\u5230\u4e00\u4e2a\u6bd4\u8f83\u597d\u7528\u7684\u65b9\u6cd5<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>4<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4922094\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : QuinceyWu <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             github \u4e0a\u6709\u4e2a\u5206\u5e03\u5f0f\u722c\u866b\u7ba1\u7406\u53eb Crawlab\uff0c\u6211\u73b0\u5728\u5c31\u5728\u7528\uff0c\u80fd\u6ee1\u8db3\u4f60\u6240\u6709\u722c\u866b\u9700\u6c42                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4922095\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : tuoov <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             subprocess.Popen([&#8216;python&#8217;,&#8217;runSpider.py&#8217;])<br \/>process.start()\u653e\u5230 runSpider \u91cc\uff0c\u547d\u4ee4\u884c\u4f20\u53c2\u51b3\u5b9a\u542f\u52a8\u7684\u722c\u866b<br \/>\u4e5f\u8bb8\u80fd\u89e3\u51b3\u4f60\u7684\u95ee\u9898                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4922096\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : Luzaiv7 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @QuinceyWu \u611f\u89c9\u8fd9\u4e2a\u633a\u9002\u5408\u6211\u7684\uff0c\u8c22\u8c22                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4922097\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : Luzaiv7 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @tuoov \u5df2\u7ecf\u89e3\u51b3\u4e86\uff0c\u8c22\u8c22                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u591a\u4e2a scrapy \u722c\u866b\u542f\u52a8\u95ee\u9898 &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\/277400"}],"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=277400"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/277400\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=277400"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=277400"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=277400"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}