Python 3 - Get text from tag in beautifulSoup

前端 未结 2 822
借酒劲吻你
借酒劲吻你 2020-12-21 23:46

I am using beautifulSoup to extract data from website. Text from that website changes everytime you reload your page so basically I wish to be able to set a focus on the cla

相关标签:
2条回答
  • 2020-12-22 00:19
    1. You can use text or string attribute of the element.

      elems = soup.find_all(True, class_='template_title')
      print([elem.string for elem in elems])
      # prints `['4']` for the given html snippet
      
    2. Specify more attributes as you want:

      elems = soup.find_all(True, class_='template_title',
                            height='50', valign='bottom', width='535')
      
    0 讨论(0)
  • 2020-12-22 00:19
    1. i usually use .get_text()

    2. yes,you can

      there is a method : .find_all(name, attrs, recursive, string, limit, **kwargs)

      **kwargs :recive anything like height ,valign ,width

      or

      attrs = {'height':'50','valign':'bottom'}

    0 讨论(0)
提交回复
热议问题