beautifulsoup检索日期

纯香草

我正在尝试从产品页面检索日期: http://www.homedepot.com/p/Husky-41-in-16-Drawer-Tool-Chest-and-Cabinet-Set-HOTC4016B1QES/205080371

但是日期隐藏在元信息中,请参见第一行:

<meta itemprop="datePublished" content="2014-11-27" />
</div><div id='80886327' itemprop="review" itemscope itemtype="http://schema.org/Review"><meta itemprop="itemReviewed" content="HUSKY 41 in. 16-Drawer Tool Chest and Cabinet Set" /><span itemprop="reviewRating" itemscope itemtype="http://schema.org/Rating">Rated <span itemprop="ratingValue">5</span> out of <span itemprop="bestRating">5</span></span>Â by <span itemprop="author">Razor</span><span itemprop="name"> solid construction
</span><span itemprop="description"> I spent the last month checking and looking at all tool boxes that I could find. Online and at available stores. In comparison to all, this is by far the best deal for the money. Quality, workmanship and construction of this is by far the best for the money. Some I looked at are twice as much money for the same quality... I have had this approx. a month and filled with tools and shop stuff and with the ball bearing drawers loaded, does not make any difference on drawer operation. Granted we still need the test of time..

你们知道如何将这些日期保存到列表中吗?

ec

您可以使用find_all()来获取所有meta标签itemprop="datePublished"

import urllib2
from bs4 import BeautifulSoup

url = 'http://www.homedepot.com/p/Husky-41-in-16-Drawer-Tool-Chest-and-Cabinet-Set-HOTC4016B1QES/205080371'
soup = BeautifulSoup(urllib2.urlopen(url=url))

print [meta.get('content') for meta in soup.find_all('meta', itemprop='datePublished')]

印刷:

[
    '2014-11-27', 
    '2014-11-20', 
    '2014-12-15', 
    '2014-10-28', 
    '2014-10-10'
]

或者,使用CSS Selector

print [meta.get('content') for meta in soup.select('meta[itemprop="datePublished"]')]

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

BeautifulSoup 不检索元素

来自分类Dev

检索日期差异php

来自分类Dev

使用Xpath检索日期

来自分类Dev

从日期检索星期数

来自分类Dev

无法从MySQL检索日期

来自分类Dev

Python / BeautifulSoup:检索“ href”属性

来自分类Dev

使用 BeautifulSoup 检索图像链接

来自分类Dev

无法使用 BeautifulSoup 检索 href

来自分类Dev

使用beautifulsoup困难检索信息

来自分类Dev

BeautifulSoup 无法检索网页链接

来自分类Dev

使用BeautifulSoup获取日期

来自分类Dev

仅检索日期时间中的日期

来自分类Dev

检索基于数据的日期mongodb

来自分类Dev

按日期检索行:cassandra

来自分类Dev

检索后天日期查询

来自分类Dev

检索最新日期的oracle

来自分类Dev

检索后天日期查询

来自分类Dev

无法使用BeautifulSoup检索所需XPATH的元素

来自分类Dev

使用BeautifulSoup遍历并检索特定的URL

来自分类Dev

如何使用Beautifulsoup检索<th> <td>

来自分类Dev

Python BeautifulSoup:从div标签检索文本

来自分类Dev

使用BeautifulSoup根据属性检索信息

来自分类Dev

使用BeautifulSoup从跨度部分检索值

来自分类Dev

使用beautifulSoup检索html标签内容

来自分类Dev

从BeautifulSoup中的元素检索文本值

来自分类Dev

无法使用 BeautifulSoup 检索页面内容

来自分类Dev

检索日期在开始日期和结束日期之间的记录

来自分类Dev

Laravel 5:如何根据日期检索记录?

来自分类Dev

在Firebase中保存和检索日期