Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用BeautifulSoup在python中搜索id_Python_Module_Beautifulsoup - Fatal编程技术网

使用BeautifulSoup在python中搜索id

使用BeautifulSoup在python中搜索id,python,module,beautifulsoup,Python,Module,Beautifulsoup,我需要帮助解决一个问题。。。我正在做一个知道标签内容的代码,但是。。。如果内容有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') # <-- PRO

我需要帮助解决一个问题。。。我正在做一个知道标签内容的代码,但是。。。如果内容有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
从bs4导入美化组
导入urllib2
代码='15,00欧元'
汤=美汤(代码)

price=soup.find('a',id='v4-27')#如果这是html代码,则应将
'a'
标记替换为
'span'
标记。应该是这样的

    ...
    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

哈哈,我需要睡觉,谢谢!