私は、scrapy-splashを使用して、Web ページのスクリーンショットを作成し、いくつかのメタデータを含む png を出力しています。スクレイピーは、エンジンが実行するすべてのアクションをタイムスタンプなどでログに記録することを知っていますが、スパイダーでその情報にアクセスしてアイテムに渡す方法を理解するのに苦労しています。アドバイスやヒントをいただければ幸いです。
必要なメタデータ: 1) ターゲット サイトの IP。2) ページ読み込み時のタイムスタンプ (UTC)。3) ページキャプチャ時のタイムスタンプ (UTC)
import json
import base64
import scrapy
from scrapy_splash import SplashRequest
from project_spider.screenshot_format import PDF
class screenshot(scrapy.Spider):
name = 'screenshot'
def start_requests(self):
url = 'http://www.gxjjw.gov.cn/staticpages/20171109/gxjjw5a03a8bc-
128325.shtml'
splash_args = {
'wait': 3.0,
'html': 1,
'png': 1,
'width': 600,
'render_all': 1,
'wait': 3.0,
}
yield SplashRequest(url, self.parse_result, endpoint='render.json',
args=splash_args)
def parse_result(self, response):
png_b64 = response.data['png']
header = 'data:image/png;base64,'
png_b64 = header + png_b64
# Meta-data variables will go here