예제 #1
0
def parse_response(response):
    """Parse raw XML API response.

    The method tries its best to iterate over a set of items without crashing,
    since a bad item shouldn't prevent the scraper to aggregate the others.
    """
    tree = Selector(response).root

    for node in tree.findall('{gml}featureMembers/'.format(**XMLNS)):
        try:
            yield _parse_node(response.url, node)
        except Exception as e:
            logger.warning('failed to parse node: %s', e)
            # unfortunately it happens and then should be fixed, but it
            # shouldn't prevent the other items to be scrapped
            continue
예제 #2
0
 def test_xml_node_extraction(self):
     tree = Selector(self.mock_api_result).root
     for node in tree.findall(
             '{gml}featureMembers/'.format(**constants.XMLNS)):
         self.assertEqual(parser.extract(node, 'source'),
                          FIXTURE_VESSEL['ais_type'])