python - 使用 Splash Scrapy POST 到 Javascript 生成的表单

标签 python web-scraping scrapy splash-screen scrapyjs

我有以下蜘蛛,它几乎只是应该发布到表单。 但我似乎无法让它发挥作用。当我通过 Scrapy 执行此操作时,响应从未显示。 有人可以告诉我我哪里出了问题吗?

这是我的蜘蛛代码:

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import scrapy
from scrapy.http import FormRequest
from scrapy.shell import inspect_response


class RajasthanSpider(scrapy.Spider):
    name = "rajasthan"
    allowed_domains = ["rajtax.gov.in"]
    start_urls = (
        'http://www.rajtax.gov.in/',
    )

    def parse(self, response):
        return FormRequest.from_response(
            response,
            formname='rightMenuForm',
            formdata={'dispatch': 'dealerSearch'},
            callback=self.dealer_search_page)

    def dealer_search_page(self, response):

        yield FormRequest.from_response(
            response,
            formname='dealerSearchForm',
            formdata={
                "zone": "select",
                "dealertype": "VAT",
                "dealerSearchBy": "dealername",
                "name": "ana"
            }, callback=self.process)

    def process(self, response):
        inspect_response(response, self)

我得到的是这样的回复: No result Found

我应该得到的是这样的结果: Results Found

当我用 Splash 替换我的 dealer_search_page() 时:

def dealer_search_page(self, response):

    yield FormRequest.from_response(
        response,
        formname='dealerSearchForm',
        formdata={
            "zone": "select",
            "dealertype": "VAT",
            "dealerSearchBy": "dealername",
            "name": "ana"
        },
        callback=self.process,
        meta={
            'splash': {
                'endpoint': 'render.html',
                'args': {'wait': 0.5}
            }
        })

我收到以下警告:

2016-03-14 15:01:29 [scrapy] WARNING: Currently only GET requests are supported by SplashMiddleware; <POST http://rajtax.gov.in:80/vatweb/dealerSearch.do> will be handled without Splash

程序在到达 process() 函数中的 inspect_response() 之前退出。

该错误表明 Splash 尚不支持 POSTSplash 是否适用于此用例,或者我应该使用 Selenium

最佳答案

现在 Splash 支持 POST 请求。尝试 SplashFormRequest{'splash':{'http_method':'POST'}}

基于https://github.com/scrapy-plugins/scrapy-splash

关于python - 使用 Splash Scrapy POST 到 Javascript 生成的表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35968831/

相关文章:

python - 组成:为什么 "container instance"改变时 "contained instance"属性没有更新?

python - 在 Python 中使用 QT Designer (.ui) 文件时如何启用 QDropEvent?

python - 使用 Python 语音识别时的说话人分类

python - 使用 bs4 和 Python 从 html 表格中提取数据

python - Xpath 中的空文本

python - 如何从一个链接生成已解析的项目以及同一项目列表中其他链接的其他已解析的项目

python - 我在从 scrapy 蜘蛛下载/抓取图像时遇到值错误,我正在使用图像管道

python - 为什么这种模拟退火算法应用于TSP不收敛?

jquery - 使用 Scrapy 通过无限滚动 Ajax 提取数据

Python网络爬虫,通过链接爬取并找到特定的词