Parse HTTP response and return a list of HTMLForm instances. The return value of urllib2.urlopen can be conveniently passed to this function as the response parameter. ClientForm.ParseError is raised on parse errors. response: file-like object (supporting read() method) with a met
(response, *args, **kwds)
| 1010 | ) |
| 1011 | |
| 1012 | def ParseResponse(response, *args, **kwds): |
| 1013 | """Parse HTTP response and return a list of HTMLForm instances. |
| 1014 | |
| 1015 | The return value of urllib2.urlopen can be conveniently passed to this |
| 1016 | function as the response parameter. |
| 1017 | |
| 1018 | ClientForm.ParseError is raised on parse errors. |
| 1019 | |
| 1020 | response: file-like object (supporting read() method) with a method |
| 1021 | geturl(), returning the URI of the HTTP response |
| 1022 | select_default: for multiple-selection SELECT controls and RADIO controls, |
| 1023 | pick the first item as the default if none are selected in the HTML |
| 1024 | form_parser_class: class to instantiate and use to pass |
| 1025 | request_class: class to return from .click() method (default is |
| 1026 | _urllib.request.Request) |
| 1027 | entitydefs: mapping like {"&": "&", ...} containing HTML entity |
| 1028 | definitions (a sensible default is used) |
| 1029 | encoding: character encoding used for encoding numeric character references |
| 1030 | when matching link text. ClientForm does not attempt to find the encoding |
| 1031 | in a META HTTP-EQUIV attribute in the document itself (mechanize, for |
| 1032 | example, does do that and will pass the correct value to ClientForm using |
| 1033 | this parameter). |
| 1034 | |
| 1035 | backwards_compat: boolean that determines whether the returned HTMLForm |
| 1036 | objects are backwards-compatible with old code. If backwards_compat is |
| 1037 | true: |
| 1038 | |
| 1039 | - ClientForm 0.1 code will continue to work as before. |
| 1040 | |
| 1041 | - Label searches that do not specify a nr (number or count) will always |
| 1042 | get the first match, even if other controls match. If |
| 1043 | backwards_compat is False, label searches that have ambiguous results |
| 1044 | will raise an AmbiguityError. |
| 1045 | |
| 1046 | - Item label matching is done by strict string comparison rather than |
| 1047 | substring matching. |
| 1048 | |
| 1049 | - De-selecting individual list items is allowed even if the Item is |
| 1050 | disabled. |
| 1051 | |
| 1052 | The backwards_compat argument will be deprecated in a future release. |
| 1053 | |
| 1054 | Pass a true value for select_default if you want the behaviour specified by |
| 1055 | RFC 1866 (the HTML 2.0 standard), which is to select the first item in a |
| 1056 | RADIO or multiple-selection SELECT control if none were selected in the |
| 1057 | HTML. Most browsers (including Microsoft Internet Explorer (IE) and |
| 1058 | Netscape Navigator) instead leave all items unselected in these cases. The |
| 1059 | W3C HTML 4.0 standard leaves this behaviour undefined in the case of |
| 1060 | multiple-selection SELECT controls, but insists that at least one RADIO |
| 1061 | button should be checked at all times, in contradiction to browser |
| 1062 | behaviour. |
| 1063 | |
| 1064 | There is a choice of parsers. ClientForm.XHTMLCompatibleFormParser (uses |
| 1065 | HTMLParser.HTMLParser) works best for XHTML, ClientForm.FormParser (uses |
| 1066 | sgmllib.SGMLParser) (the default) works better for ordinary grubby HTML. |
| 1067 | Note that HTMLParser is only available in Python 2.2 and later. You can |
| 1068 | pass your own class in here as a hack to work around bad HTML, but at your |
| 1069 | own risk: there is no well-defined interface. |
no test coverage detected
searching dependent graphs…