【发布时间】:2017-01-24 16:42:13
【问题描述】:
我用python做了一个爬虫。
但我的爬虫以这种格式获取日期:
s = page_ad.findAll('script')[25].text.replace('\'', '"')
s = re.search(r'\{.+\}', s, re.DOTALL).group() # get json data
s = re.sub(r'//.+\n', '', s) # replace comment
s = re.sub(r'\s+', '', s) # strip whitspace
s = re.sub(r',}', '}', s) # get rid of last , in the dict
dataLayer = json.loads(s)
print dataLayer["page"]["adDetail"]["adDate"]
2017-01-1412:28:07
我只想要没有时间的日期 (2017-01-14),如果没有空格,如何只获取日期?
【问题讨论】:
-
您应该提供minimal reproducible example。就目前而言,没有人知道你实际上在做什么来获得那个日期。
-
切掉结尾:
date[:10]
标签: python python-2.7 datetime python-2.x