0

I know Beautiful Soup does not support xpath expressions. Thus I end up writing code that looks like this:

soup.findChildren(['table'])[0].findChildren(['tr'])[0].findChildren(['td'])[0]

UGLY! Is there a cleaner and more direct way to write these kinds of chains without xpath using Beautiful Soup. I do not want to use lxml because it has trouble parsing my HTML.

can we use xpath with BeautifulSoup?

Community
  • 1
  • 1
bernie2436
  • 22,841
  • 49
  • 151
  • 244
  • 1
    You are specifying which of all tables and which of its rows you want the children of, looks concise to me ( well, precise, at least). What would an XPath query look like that would be easier on the eyes? – Anthony Feb 14 '14 at 16:11
  • One Google search and I found at least one solution to your problem. http://stackoverflow.com/questions/11465555/can-we-use-xpath-with-beautifulsoup – NaviSaysListen Feb 14 '14 at 16:15

0 Answers0