【发布时间】:2012-08-05 18:42:16
【问题描述】:
我正在解析销售电子产品的网站.. 具体来说,我希望收集产品的名称和价格 我在解析基于 xml 的网站时遇到了一个小问题......
这是我的代码:
>>> import urllib2
>>> from bs4 import BeautifulSoup
>>> url=urllib2.urlopen("http://store.explorelabs.com/index.php?main_page=products_all")
>>> soup=BeautifulSoup(url,"xml")
>>> data=soup.find_all(colspan="2")
上面的代码有效
现在当我这样做时(因为名称在强标签内)
>>> data.strong
或
>>> data.attrs
它告诉我这个:
Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
data.strong
AttributeError: 'ResultSet' object has no attribute 'strong'
或
Traceback (most recent call last):
File "<pyshell#17>", line 1, in <module>
data.find_all('a')
AttributeError: 'ResultSet' object has no attribute 'find_all'
我正在尝试迭代并尝试了解更多信息。
任何指针都会非常有帮助。
【问题讨论】:
-
欢迎来到 Stack Overflow!我已经为你格式化了你的代码块;下次查看How do I format my code blocks? 寻求帮助。
-
另外请注意,在 Stack Overflow 上,我们都可以通过编辑来帮助改进您的帖子。如果你回滚这些编辑,你就会撤消那些试图帮助你的人的工作。
-
@MartijnPieters 我很抱歉,感谢您的友好:)
标签: python xml web-scraping beautifulsoup