Scrapy 选择具有刮擦飞溅和屏幕截图的元素

Scrapy 选择具有刮擦飞溅和屏幕截图的元素,scrapy,web-crawler,scrapy-spider,scrapy-splash,Scrapy,Web Crawler,Scrapy Spider,Scrapy Splash,当使用刮花飞溅,我试图去一个下拉列表,并选择在这种情况下香草。从下拉列表中选择后,我需要截图,我目前正在工作。这是我到目前为止所拥有的 class TestSpider(scrapy.Spider): name = 'test' def start_requests(self): splash_args = { 'png': 1, 'render_all': 1, 'wait': 2,

当使用刮花飞溅,我试图去一个下拉列表,并选择在这种情况下香草。从下拉列表中选择后,我需要截图,我目前正在工作。这是我到目前为止所拥有的

class TestSpider(scrapy.Spider):
    name = 'test'

    def start_requests(self):
        splash_args = {
            'png': 1,
            'render_all': 1,
            'wait': 2,
        }
        url = 'https://developer.mozilla.org/en-US/docs/Web/Events/change'

        yield SplashRequest(
            url,
            endpoint='render.html',
            args=splash_args
        )
        yield scrapy.Request(
            f"http://192.168.99.100:8050//render.png?url={url}&wait=2&render_all=1",
            self.parse_request,
        )

    def parse_request(self, response):
        with open('request.png', 'wb') as f:
            f.write(response.body)

您可以通过js_源参数传递一个js脚本以在splash_参数中运行。在您的情况下,您可能希望执行以下操作:

splash_args = {
   'png': 1,
   'render_all': 1,
   'wait': 2,
   'js_source': 'document.getElementById("mySelect").value = "Vanilla";'
}