{"id":151,"date":"2020-07-21T08:39:49","date_gmt":"2020-07-21T00:39:49","guid":{"rendered":"http:\/\/www.gaoxigang.com\/?p=151"},"modified":"2020-07-21T08:39:49","modified_gmt":"2020-07-21T00:39:49","slug":"scrapy-%e7%88%ac%e8%99%ab%e6%a1%86%e6%9e%b6-%e8%87%aa%e5%8a%a8%e7%99%bb%e5%bd%95%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"https:\/\/www.gaoxigang.com\/index.php\/2020\/07\/21\/scrapy-%e7%88%ac%e8%99%ab%e6%a1%86%e6%9e%b6-%e8%87%aa%e5%8a%a8%e7%99%bb%e5%bd%95%e5%ae%9e%e7%8e%b0\/","title":{"rendered":"Scrapy \u722c\u866b\u6846\u67b6-\u81ea\u52a8\u767b\u5f55\u5b9e\u73b0"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u521b\u5efa\u65b0\u7684spider\u6b65\u9aa4<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong>1\u3001\u521b\u5efa\u9879\u76ee\uff1ascrapy startproject renren<br>2\u3001\u8fdb\u5165\u76ee\u5f55\u521b\u5efa\u65b0\u722c\u866b\uff1ascrapy genspider renren_spider renren.com<br>3\u3001settings.py\u914d\u7f6e\u722c\u866b\u673a\u5668\u4eba\u89c4\u5219ROBOTSTXT_OBEY\u4e3aFalse<br>4\u3001settings.py\u914d\u7f6e\u534f\u8bae\u5934\u4fe1\u606fDEFAULT_REQUEST_HEADERS\u4e2d\u6dfb\u52a0User-Agent\u4fe1\u606f<br>5\u3001\u9879\u76ee\u4e0b\u521b\u5efa\u542f\u52a8\u9875start_renren.py<\/strong><\/p><\/blockquote>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from scrapy.cmdline import execute\nexecute(\"scrapy crawl renren_spider\".split(' '))<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u767b\u5f55\u9a8c\u8bc1\u7684API\u63a8\u8350<\/h2>\n\n\n\n<ol class=\"wp-block-list\"><li>\u6ed1\u52a8\u9a8c\u8bc1\u7801\u7834\u89e3\u5e73\u53f0\uff1ahttp:\/\/api.4xx3.cn\/<\/li><li>\u4e91\u6253\u7801\uff1ahttp:\/\/www.yundama.com\/price.html<\/li><li>\u8d85\u7ea7\u9e70\uff1ahttp:\/\/www.chaojiying.com\/cases.html<\/li><\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">\u5982\u4f55\u53d1\u9001\u767b\u5f55\u8868\u5355<\/h2>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\u7531\u4e8e\u662f\u8868\u5355\uff0c\u5fc5\u987b\u53d1\u9001\u4e00\u4e2aPost\u8bf7\u6c42\uff0c\u56e0\u6b64\u521b\u5efaFromRequest\u8bf7\u6c42\uff0c\u5e76\u4e14\u8bbe\u7f6e\u767b\u5f55\u6210\u529f\u540e\u8981\u6267\u884c\u7684\u65b9\u6cd5<\/p><\/blockquote>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">class JsSpider(scrapy.Spider):\n    name = 'js'\n    allowed_domains = ['renren.com']\n    # \u8d77\u59cb\u5730\u5740\u4e3a\u767b\u5f55\u9875\u9762, \u767b\u5f55\u6210\u529f\u540e\u5728\u8fdb\u884c\u722c\u53d6\u64cd\u4f5c\n    start_urls = ['http:\/\/www.renren.com\/SysHome.do']\n\n    def parse(self, response):\n        # 1: \u8fd4\u56de\u7684\u662f\u767b\u5f55\u9875\u9762\u7684\u6570\u636e\n        # 2: \u521b\u5efa\u8868\u5355,\u5e76\u4e14\u586b\u5199\u6b63\u786e\u7684\u8d26\u6237\u7684\u5bc6\u7801\n        loginForm = {\n            'email': '970138074@qq.com',\n            'password': 'pythonspider',\n        }\n        return scrapy.FormRequest(url=\"http:\/\/www.renren.com\/PLogin.do\",formdata=loginForm,callback=self.after_login)\n\n    def after_login(self,reponse):\n        with open('books.html', 'w+',encoding=\"UTF-8\") as f:\n            f.write(reponse.text)\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u767b\u5f55\u6210\u529f\u5219\u4f1a\u6267\u884cafter_login\u65b9\u6cd5\uff0c\u6b64\u65b9\u6cd5\u4f1a\u628a\u767b\u5f55\u6210\u529f\u4e4b\u540e\u7684\u9875\u9762\u4e0b\u8f7d\u5230\u672c\u5730\uff0c\u4e0b\u8f7d\u65f6\u8bbe\u7f6e\u7684\u7f16\u7801\u53d6\u51b3\u4e8e\u76ee\u6807\u7f51\u9875\u7684\u7f16\u7801<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u521b\u5efa\u65b0\u7684spider\u6b65\u9aa4 1\u3001\u521b\u5efa\u9879\u76ee\uff1ascrapy startproject renren2\u3001\u8fdb\u5165\u76ee\u5f55\u521b\u5efa\u65b0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-151","post","type-post","status-publish","format-standard","hentry","category-biji"],"_links":{"self":[{"href":"https:\/\/www.gaoxigang.com\/index.php\/wp-json\/wp\/v2\/posts\/151","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gaoxigang.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gaoxigang.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gaoxigang.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gaoxigang.com\/index.php\/wp-json\/wp\/v2\/comments?post=151"}],"version-history":[{"count":0,"href":"https:\/\/www.gaoxigang.com\/index.php\/wp-json\/wp\/v2\/posts\/151\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.gaoxigang.com\/index.php\/wp-json\/wp\/v2\/media?parent=151"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gaoxigang.com\/index.php\/wp-json\/wp\/v2\/categories?post=151"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gaoxigang.com\/index.php\/wp-json\/wp\/v2\/tags?post=151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}