Skip to content

Instantly share code, notes, and snippets.

@alecxe
Created August 13, 2014 19:25
Show Gist options
  • Save alecxe/ae7807884390ee06fcda to your computer and use it in GitHub Desktop.
Save alecxe/ae7807884390ee06fcda to your computer and use it in GitHub Desktop.
import xml.etree.ElementTree as ET
from bs4 import BeautifulSoup
data = """
<table>
<tr align="right"><td>193</td><td>Dalton</td><td>Daisy</td></tr>
<tr align="right"><td>194</td><td>Dakota</td><td>Amelia</td></tr>
<tr align="right"><td>195</td><td>Julio</td><td>Mayra</td></tr>
<tr align="right"><td>196</td><td>Arthur</td><td>Theresa</td></tr>
<tr align="right"><td>197</td><td>Pedro</td><td>Madeline</td></tr>
<tr align="right"><td>198</td><td>Preston</td><td>Sasha</td></tr>
<tr align="right"><td>199</td><td>Cesar</td><td>Claudia</td></tr>
</table>
"""
tree = ET.fromstring(data)
print [element.text for element in tree.findall('.//tr/td[2]')]
soup = BeautifulSoup(data)
print [element.text for element in soup.select('table > tr > td:nth-of-type(2)')]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment