【发布时间】:2010-10-23 16:34:31
【问题描述】:
我正在尝试解析来自购物网站的视频游戏标题列表。但是,由于项目列表都存储在标签内。
This 文档的部分据说解释了如何仅解析文档的一部分,但我无法解决。我的代码:
from BeautifulSoup import BeautifulSoup
import urllib
import re
url = "Some Shopping Site"
html = urllib.urlopen(url).read()
soup = BeautifulSoup(html)
for a in soup.findAll('a',{'title':re.compile('.+') }):
print a.string
目前是在任何具有非空标题引用的标签内打印字符串。但它也将侧栏中的项目作为“特价”。如果我只能拿产品列表div,我会用一块石头杀死2只鸟。
非常感谢。
【问题讨论】:
标签: python beautifulsoup scrape