使用Beautiful Soup提取整个html标记(包括子标记)

时间:2016-09-07 21:47:07

标签: python html beautifulsoup

我试图提取HTML元素的整个内容,然后我要解析。更确切地说,我有一个网页,我抓了一个网页,我可以用Beautiful Soup识别<select>标签,但我想访问它的子标签。

到目前为止,我有:

import urllib2
from BeautifulSoup import BeautifulSoup as BS

search_url = 'http://example.com/'
response = urllib2.urlopen(self.search_url)
html = response.read()

soup = BS(html)
html_manufacturer_list = soup.findAll("select", attrs = {"id":"manufacturerID"})

实际的HTML我解析如下:

<select id="manufacturerID">
   <option value="1">Abarth</option>
   <option value="2">ABC</option>
   <option value="3">Acura</option>
   <option value="4">Alfa Romeo</option>
   ...
</select>

但是,在运行上述Python代码时,html_manufacturer_list对象仅识别父select标记,并且没有与其子option标记相关的信息。

<select id="manufacturerID"> </select>

搜索<option>代码是..不是一个选项,因为网页上有多个带有选项的<select>代码。

如何从页面中识别或提取<option>标记信息,我们非常感谢您提供任何建议或帮助。

0 个答案:

没有答案
相关问题