2016-11-26 81 views
-1

我是scrapy的新手,我搜索了很多,但我找不到任何可以顯示如何使用scrapy登錄的工作示例。Scrapy和github登錄

我準備這個github上登錄代碼來了解流量模式,但好像它是不工作...

誰能告訴我怎樣才能做到這一點?

在此先感謝。

import scrapy 
from scrapy.spider import BaseSpider 
from scrapy.http import FormRequest 

class SpiderOne(BaseSpider): 
name = "spider" 
allowed_domains = ["github.com"] 
start_urls = ["https://github.com/login"] 

def parse(self, response): 
    print "in parse function" 
    return [FormRequest.from_response(
     response, 
     url='https://github.com/session', 
     method="POST", 
     formdata={ 
      'login':'valid_email', 
      'password':'valid_password' 
     }, 
     callback=self.after_login() 
    )] 

def after_login(self, response): 

    print "in after_login function" 
    print response 

回答

0

您應該嘗試這樣

def parse(self, response): 
    print "in parse function" 
    yield FormRequest.from_response(
    response, 
    url='https://github.com/session', 
    method="POST", 
    formdata={ 
     'login':'valid_email', 
     'password':'valid_password' 
    }, 
    callback=self.after_login) 
+0

非常感謝!現在我獲得狀態200. – abhishake

+0

非常感謝如果您接受此答案 – Prabhakar

+0

完成! 如果你能告訴我,我怎樣才能趕上github的下一個響應,我會非常感謝你! 我已經提出了一個請求:https://github.com/session ,我得到了這個迴應的結果:https://github.com/ 此外,我是否需要設置cookie以繼續爬行? – abhishake