Python 3 - Get text from tag in beautifulSoup

前端 未结 2 825
借酒劲吻你
借酒劲吻你 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')
      

提交回复
热议问题