Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions microdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ def _text(e):
chunks = []
if e.nodeType == e.TEXT_NODE:
chunks.append(e.data)
elif e.tagName == 'script':
return ''
for child in e.childNodes:
chunks.append(_text(child))
return ''.join(chunks)
Expand Down
3 changes: 3 additions & 0 deletions test-data/example.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
<span itemprop="streetAddress">
20341 Whitworth Institute
405 N. Whitworth
<script>
// Unrelated text
</script>
</span>
<span itemprop="addressLocality">Seattle</span>,
<span itemprop="addressRegion">WA</span>
Expand Down
3 changes: 3 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def test_parse(self):
self.assertEqual(item.address.itemtype, [URI("http://schema.org/PostalAddress")])
self.assertTrue(item.address.addressLocality, "Seattle")

# <script> tag should be ignored in the content text
self.assertFalse("Unrelated text" in item.address.streetAddress)

# json
i = json.loads(item.json())
self.assertEqual(i["properties"]["name"][0], "Jane Doe")
Expand Down