<reponame>1365102044/lwscrapy
# -*- coding: utf-8 -*-
import scrapy


class RenrenSpider(scrapy.Spider):
    name = 'renren'
    allowed_domains = ['renren.com', 'httpbin.org/user-agent', 'www.baidu.com']
    start_urls = ['http://renren.com/']


    # 重写 自定义开始请求
    # def start_requests(self):
    #     url = 'http://www.renren.com/PLogin.do'
    #     data = {'email': '<EMAIL>',
    #             'password': '<PASSWORD>'}
    #     request = scrapy.FormRequest(url=url, formdata=data, callback=self.login_prase)
    #     yield request
    #
    # def login_prase(self, response):
    #     print(response.text)
    #     with open('login_res.html', 'w', encoding='utf-8') as ft:
    #         ft.write(response.text)


    # 测试 动态请求头
    def start_requests(self):
        # url = 'httpbin.org/user-agent'
        url = 'http://www.baidu.com'
        request = scrapy.Request(url = url, callback = self.res_prase)
        yield request


    def res_prase(self,response):
        print(response.text)

# -*- coding: utf-8 -*-
import scrapy


class RenrenSpider(scrapy.Spider):
    name = 'renren'
    allowed_domains = ['renren.com', 'httpbin.org/user-agent', 'www.baidu.com']
    start_urls = ['http://renren.com/']


    # 重写 自定义开始请求
    # def start_requests(self):
    #     url = 'http://www.renren.com/PLogin.do'
    #     data = {'email': '<EMAIL>',
    #             'password': '<PASSWORD>'}
    #     request = scrapy.FormRequest(url=url, formdata=data, callback=self.login_prase)
    #     yield request
    #
    # def login_prase(self, response):
    #     print(response.text)
    #     with open('login_res.html', 'w', encoding='utf-8') as ft:
    #         ft.write(response.text)


    # 测试 动态请求头
    def start_requests(self):
        # url = 'httpbin.org/user-agent'
        url = 'http://www.baidu.com'
        request = scrapy.Request(url = url, callback = self.res_prase)
        yield request


    def res_prase(self,response):
        print(response.text)
# -*- coding: utf-8 -*- # 重写 自定义开始请求 # def start_requests(self): #     url = 'http://www.renren.com/PLogin.do' #     data = {'email': '<EMAIL>', #             'password': '<PASSWORD>'} #     request = scrapy.FormRequest(url=url, formdata=data, callback=self.login_prase) #     yield request # # def login_prase(self, response): #     print(response.text) #     with open('login_res.html', 'w', encoding='utf-8') as ft: #         ft.write(response.text) # 测试 动态请求头 # url = 'httpbin.org/user-agent'