使用 javscript 和 ajax 进行网页抓取登录

问题描述

我一直在尝试获取视图状态数据以通过表单身份验证。这是我的代码

import scrapy
from scrapy_splash import SplashRequest,SplashFormRequest

class BrpSplashSpider(scrapy.Spider):
    name = 'brp_splash'
    allowed_domains = ['brp.secure.force.com']
   # start_urls = ['http://brp.secure.force.com/']     

    script = '''
        function main(splash,args)
        url = args.url
        assert(splash:go(url))
        assert(splash:wait(1))
        return splash:html() 
        end
    '''
    def start_requests(self):
        yield SplashRequest(
            url='https://brp.secure.force.com/login',endpoint = 'execute',args = {
                'lua_source':self.script
            },callback=self.parse
        )

    def parse(self,response):
    yield SplashFormRequest.from_response(
        response,formxpath='//form',formdata={
            'AJAXREQUEST' : '_viewRoot'
            'j_id0:j_id5' : 'j_id0:j_id5'
            'j_id0:j_id5:Login1_Dealer_No': '******'
            'j_id0:j_id5:Login1_UserName': '******'
            'j_id0:j_id5:Login1_Password': '*********'
            'j_id0:j_id5:j_id26': 'en'
            'com.salesforce.visualforce.ViewState': 
        }
    )
    pass 

检查网页并查看表单数据,我可以看到一个巨大的字符串,即视图状态数据。它不在 html 中。它在哪里,我如何引用它?

感谢您的关注,

吉姆

解决方法

我正在寻找的对象在登录页面中。我是登录后找的。新手学习曲线错误