Using beautiful soup to get html attribute value

前端 未结 2 1729
暗喜
暗喜 2021-01-24 05:05

What i\'m trying to do is use beautiful soup to get the value of an html attribute.

What i have so far is:

soup = BeautifulSoup(html, \"html.parser\")
         


        
2条回答
  •  盖世英雄少女心
    2021-01-24 05:57

    I assume your find() method returns None so you can't concatenate string at line #2.

    >>> print('' + None)                                       
    Traceback (most recent call last):                         
      File "", line 1, in                       
    TypeError: can only concatenate str (not "NoneType") to str
    

    That's an error message I get in Python 3.7
    That's not the Soup problem, you have to explicitly check return value.

    Provide more information (stacktrace) if that's not the case

提交回复
热议问题