def test_advanced_search_form(self): url = 'http://www.ebay.com/sch/ebayadvsearch/?rt=nc' body = open(join(_PATH, "data", "ebay_advanced_search.html")).read() form_descriptor = json.loads("""{ "type": "form", "form_url": "http://*****:*****@name='adv_search_from']", "fields": [ { "xpath": ".//*[@name='_nkw']", "type": "fixed", "value": "Cars" }, { "xpath": ".//*[@name='_in_kw']", "type": "all" } ] }""") start_requests = list(fill_generic_form(url, body, form_descriptor)) expected_requests = [([('_in_kw', '1'), ('_udlo', ''), ('_ex_kw', ''), ('_nkw', u'Cars'), ('_ipg', '50'), ('_adv', '1'), ('_salic', '1'), ('_dmd', '1'), ('_fsradio', '&LH_SpecificSeller=1'), ('_udhi', ''), ('_sop', '12'), ('_sasl', '')], 'http://www.ebay.com/sch/i.html', 'GET'), ([('_in_kw', '2'), ('_udlo', ''), ('_ex_kw', ''), ('_nkw', u'Cars'), ('_ipg', '50'), ('_adv', '1'), ('_salic', '1'), ('_dmd', '1'), ('_fsradio', '&LH_SpecificSeller=1'), ('_udhi', ''), ('_sop', '12'), ('_sasl', '')], 'http://www.ebay.com/sch/i.html', 'GET'), ([('_in_kw', '3'), ('_udlo', ''), ('_ex_kw', ''), ('_nkw', u'Cars'), ('_ipg', '50'), ('_adv', '1'), ('_salic', '1'), ('_dmd', '1'), ('_fsradio', '&LH_SpecificSeller=1'), ('_udhi', ''), ('_sop', '12'), ('_sasl', '')], 'http://www.ebay.com/sch/i.html', 'GET'), ([('_in_kw', '4'), ('_udlo', ''), ('_ex_kw', ''), ('_nkw', u'Cars'), ('_ipg', '50'), ('_adv', '1'), ('_salic', '1'), ('_dmd', '1'), ('_fsradio', '&LH_SpecificSeller=1'), ('_udhi', ''), ('_sop', '12'), ('_sasl', '')], 'http://www.ebay.com/sch/i.html', 'GET')] self.assertEqual(start_requests, expected_requests)
def parse_form_page(self, response): try: for (args, url, method) in fill_generic_form(response.url, response.body, response.request.meta): yield FormRequest(url, method=method, formdata=args, callback=self.after_form_page) except Exception, e: self.log(str(e), log.WARNING)
def test_advanced_search_form(self): url = 'http://www.ebay.com/sch/ebayadvsearch/?rt=nc' body = open(join(_PATH, "data", "ebay_advanced_search.html")).read() form_descriptor = json.loads("""{ "type": "form", "form_url": "http://*****:*****@name='adv_search_from']", "fields": [ { "xpath": ".//*[@name='_nkw']", "type": "fixed", "value": "Cars" }, { "xpath": ".//*[@name='_in_kw']", "type": "all" } ] }""") start_requests = list(fill_generic_form(url, body, form_descriptor)) expected_requests = [ ([('_in_kw', '1'), ('_udlo', ''), ('_ex_kw', ''), ('_nkw', u'Cars'), ('_ipg', '50'), ('_adv', '1'), ('_salic', '1'), ('_dmd', '1'), ('_fsradio', '&LH_SpecificSeller=1'), ('_udhi', ''), ('_sop', '12'), ('_sasl', '')], 'http://www.ebay.com/sch/i.html', 'GET'), ([('_in_kw', '2'), ('_udlo', ''), ('_ex_kw', ''), ('_nkw', u'Cars'), ('_ipg', '50'), ('_adv', '1'), ('_salic', '1'), ('_dmd', '1'), ('_fsradio', '&LH_SpecificSeller=1'), ('_udhi', ''), ('_sop', '12'), ('_sasl', '')], 'http://www.ebay.com/sch/i.html', 'GET'), ([('_in_kw', '3'), ('_udlo', ''), ('_ex_kw', ''), ('_nkw', u'Cars'), ('_ipg', '50'), ('_adv', '1'), ('_salic', '1'), ('_dmd', '1'), ('_fsradio', '&LH_SpecificSeller=1'), ('_udhi', ''), ('_sop', '12'), ('_sasl', '')], 'http://www.ebay.com/sch/i.html', 'GET'), ([('_in_kw', '4'), ('_udlo', ''), ('_ex_kw', ''), ('_nkw', u'Cars'), ('_ipg', '50'), ('_adv', '1'), ('_salic', '1'), ('_dmd', '1'), ('_fsradio', '&LH_SpecificSeller=1'), ('_udhi', ''), ('_sop', '12'), ('_sasl', '')], 'http://www.ebay.com/sch/i.html', 'GET') ] self.assertEqual(start_requests, expected_requests)