BeautifulSoup: extract text from anchor tag

后端 未结 5 1884
误落风尘
误落风尘 2020-12-01 00:34

I want to extract:

  • text from following src of the image tag and
  • text of the anchor tag which is inside the div class data
5条回答
  •  不思量自难忘°
    2020-12-01 01:30

    I would suggest going the lxml route and using xpath.

    from lxml import etree
    # data is the variable containing the html
    data = etree.HTML(data)
    anchor = data.xpath('//a[@class="title"]/text()')
    

提交回复
热议问题