import unittest from scrapling import Adaptor class TestParserAutoMatch(unittest.TestCase): def test_element_relocation(self): """Test relocating element after structure change""" original_html = '''

Product 1

Description 1

Product 2

Description 2

''' changed_html = '''

Product 1

Description 1

Product 2

Description 2

''' old_page = Adaptor(original_html, url='example.com', auto_match=True) new_page = Adaptor(changed_html, url='example.com', auto_match=True) # 'p1' was used as ID and now it's not and all the path elements have changes # Also at the same time testing auto-match vs combined selectors _ = old_page.css('#p1, #p2', auto_save=True)[0] relocated = new_page.css('#p1', auto_match=True) self.assertIsNotNone(relocated) self.assertEqual(relocated[0].attrib['data-id'], 'p1') self.assertTrue(relocated[0].has_class('new-class')) self.assertEqual(relocated[0].css('.new-description')[0].text, 'Description 1')