1

我需要帮助解决问题...我正在编写代码以了解标签的内容,但是...如果内容有 id,我该怎么做?

from bs4 import BeautifulSoup
import urllib2

code = '<span class="vi-is1-prcp" id="v4-27"> 15,00 EUR </span>'
soup = BeautifulSoup(code)
price = soup.find('a', id='v4-27')  # <-- PROBLEM
print price
4

1 回答 1

3

if that is the html code then you should replace the 'a' tag with a 'span' tag. It should look something like this...

    ...
    price = soup.find('span',id="v4-27")
    print price #optional price.string will give you just the 15,00 EUR
                #instead of the entire html line
于 2013-07-11T00:28:02.247 回答