BeautifulSoup to find text within <img

后端 未结 2 693
我在风中等你
我在风中等你 2021-01-14 23:25

Here is what I get back from this Python line of code

listm = soup.findAll(\'td\',{\'class\':\'thumb\'})

when I iterate over the listm, her

2条回答
  •  不思量自难忘°
    2021-01-14 23:56

    Your td elements contain some nested elements; search for the img tag within each td element, then take the alt attribute with an item lookup:

    for td in listm:
        img = td.find('img')
        if img is not None:
            print img['alt']
    

提交回复
热议问题