How can I translate this XPath expression to BeautifulSoup?

前端 未结 4 951
耶瑟儿~
耶瑟儿~ 2021-01-04 20:43

In answer to a previous question, several people suggested that I use BeautifulSoup for my project. I\'ve been struggling with their documentation and I just cannot parse it

4条回答
  •  一整个雨季
    2021-01-04 21:04

    one option is to use lxml (I'm not familiar with beautifulsoup, so I can't say how to do with it), it defaultly supports XPath

    Edit:
    try (untested) tested:

    soup.findAll('td', 'altRow')[1].findAll('a', href=re.compile(r'/.a\w+'), recursive=False)
    

    I used docs at http://www.crummy.com/software/BeautifulSoup/documentation.html

    soup should be a BeautifulSoup object

    import BeautifulSoup
    soup = BeautifulSoup.BeautifulSoup(html_string)
    

提交回复
热议问题