簡體   English   中英

Scrapy - 從 javascript 腳本響應中檢索身份驗證令牌

[英]Scrapy - Retrieve Authentication Token from javascript script response

我需要有關此特定情況的幫助。

設想

  1. 呼叫站點

http://www.example.com/index.php

我可以從<script>標簽獲取這些信息

https://www.example.com/anotherpage.php?key=ABCDFG

使用密鑰,我必須調用此端點

https://www.example.com/login.php?key=ABCD

用於檢索存儲在 javascript 響應中的 SessionID

-- omitted

private._sessID='MYSESSIONID';

-- omitted

最后,使用這個 sessionId 並執行正確的 POST 操作,我可以在我需要的所有頁面中導航。

我的僵局

我可以使用帶有正則表達式的scrapy shell regEx所有步驟(並且一切正常),但我不知道如何在開始數據提取之前在 Z3CD13A277FBC2FEA5EF64364C8B6F85Z 蜘蛛中管理這些步驟。

有人可以幫我嗎?

您需要從基礎URL http://www.example.com/index.php開始,通過調用它在啟動請求方法中調用它並寫入其其他回調並從其他端點提取信息過程。

您需要通過以下方式實現

class CrawlSpider(scrapy.CrawlSpider):

   def parse_authentication_token(self, response):
      //extract token or whatever require and then call supers parse
      yield from super().parse()

   def start_request(self):
       return Request(url, callback=self.parse_authentication_token)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM