Changeset 1813:3167f313bdbf

Show
Ignore:
Timestamp:
10/29/09 13:18:13 (9 months ago)
Author:
Ismael Carnales <icarnales@…>
Branch:
default
Message:

added dont_click attr to FormRequest?

Files:
3 modified

Legend:

Unmodified
Added
Removed
  • docs/topics/request-response.rst

    r1803 r1813  
    251251    addition to the standard :class:`Request` methods: 
    252252 
    253     .. classmethod:: FormRequest.from_response(response, [formnumber=0, formdata=None, clickdata=None, ...]) 
     253    .. classmethod:: FormRequest.from_response(response, [formnumber=0, formdata=None, clickdata=None, dont_click=False, ...]) 
    254254 
    255255       Returns a new :class:`FormRequest` object with its form field values 
     
    276276          more info. 
    277277       :type clickdata: dict 
     278 
     279       :param dont_click: If True the form data will be sumbitted without 
     280         clicking in any element. 
     281       :type clickdata: bool 
    278282 
    279283       The other parameters of this class method are passed directly to the 
  • scrapy/http/request/form.py

    r1802 r1813  
    3838 
    3939    @classmethod 
    40     def from_response(cls, response, formnumber=0, formdata=None, clickdata=None, **kwargs): 
     40    def from_response(cls, response, formnumber=0, formdata=None,  
     41                      clickdata=None, dont_click=False, **kwargs): 
    4142        encoding = getattr(response, 'encoding', 'utf-8') 
    4243        forms = ParseFile(StringIO(response.body), response.url, 
     
    5657                for v2 in v if hasattr(v, '__iter__') else [v]: 
    5758                    form.new_control('text', k, {'value': v2}) 
     59         
     60        if not dont_click: 
     61            url, body, headers = form.click_request_data(**(clickdata or {})) 
     62        else: 
     63            url, body, headers = form._switch_click('request_data') 
    5864 
    59         url, body, headers = form.click_request_data(**(clickdata or {})) 
    6065        return cls(url, method=form.method, body=body, headers=headers, **kwargs) 
  • scrapy/tests/test_http_request.py

    r1802 r1813  
    293293        self.assertEqual(urlargs['two'], ['2']) 
    294294 
     295    def test_from_response_dont_click(self): 
     296        respbody = """ 
     297<form action="get.php" method="GET"> 
     298<input type="submit" name="clickeable1" value="clicked1"> 
     299<input type="hidden" name="one" value="1"> 
     300<input type="hidden" name="two" value="3"> 
     301<input type="submit" name="clickeable2" value="clicked2"> 
     302</form> 
     303        """ 
     304        response = Response("http://www.example.com/this/list.html", body=respbody) 
     305        r1 = self.request_class.from_response(response, dont_click=True) 
     306        urlargs = cgi.parse_qs(urlparse(r1.url).query) 
     307        self.assertFalse('clickeable1' in urlargs, urlargs) 
     308        self.assertFalse('clickeable2' in urlargs, urlargs) 
     309 
    295310    def test_from_response_errors_noform(self): 
    296311        respbody = """<html></html>"""