How can I translate this XPath expression to BeautifulSoup?

前端 未结 4 952
耶瑟儿~
耶瑟儿~ 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:18

    It seems that you are using BeautifulSoup 3.1

    I suggest reverting to BeautifulSoup 3.0.7 (because of this problem)

    I just tested with 3.0.7 and got the results you expect:

    >>> soup.findAll(href=re.compile(r'/cabel'))
    [Abel, Christian]
    

    Testing with BeautifulSoup 3.1 gets the results you are seeing. There is probably a malformed tag in the html but I didn't see what it was in a quick look.

提交回复
热议问题