报废动态选择选项Scrapy

时间:2018-11-24 08:40:59

标签: javascript ajax scrapy

我有两个选择元素,其中第二个选择选项根据第一个选择元素的选项动态加载。我正在尝试在第二个select元素中删除选项值。这是我的html,JS和Scrapy代码。

<form name=studlist method="POST" action autocomplete="off">
<input type=hidden name=token value=123>
<input type=hidden name=process value=getStudList>
<label for="studCode">Classes</label>
<select  class="classlist" name=studCode onchange="getStudByClass(this.value)">
<option value="01" >First Standard </option>
<option value="02" >Second Standard </option>
</select>
<label for="Student">Classes</label>
<select  class="classlist" name=Student id=Student>  
</select>
</form>

JavaScript

  function getStudByClass(studCode) {
   if(studId !== '') {
   var options = '';
   var optionDefault = '<option value="">Select Students </option>';
   $.ajax({
        url: JS_AJAX+'student_dtail_ajax.php',
        type: "POST",
        data: {'process': 'getStudList', studCode: studCode},
        dataType: 'json',
        beforeSend: function () {
            $("#Student").html("<option value=''>Loading...</option>");
        },
        success: function (data) {
            data=data['data'];
            for (k in data) {
                options += '<option value="' + data[k]['studId'] + '" >' + data[k]['studName'] + '</option>';
            }
            $("#Student").html(optionDefault + options);
        },
        complete: function () {
        }
    });
}

当我选择第一个选择元素的第一个选项时,控制台中的Chrome Console NETWORK XHR选项卡将提供

Request URL: http://testsite.com/student_detail_ajax.php
Request METHOD: POST

Form Data
process: getStudList
studCode : 01

Response
{"data":[ 
          { "StudId" : "1001","StudName": "Titto"},
          { "StudId" : "1002","StudName": "Johny"}
        ]
}

我正在尝试使用下面的抓取代码从第二个选择选项中抓取内容

allowed_domains = ['testsite.com']
start_urls = ['http://testsite.com/studSearch.php']

def parse(self,response):
   yield scrapy.FormRequest(
       'http://testsite.com/student_detail_ajax.php',
        formdata = {'process': 'getStudList','studCode': '01'},
        callback = self.parse_students
        )

def parse_students(self, response):
    print(response.body)

我试图静态传递studCode,但没有得到响应。有人对此有想法吗?

0 个答案:

没有答案