大神好,我在python中,想在
http://paper.people.com.cn/rm...
后面加上一年的年月日,
就是变成:
http://paper.people.com.cn/rm...
http://paper.people.com.cn/rm...
http://paper.people.com.cn/rm...
http://paper.people.com.cn/rm...
....
http://paper.people.com.cn/rm...
http://paper.people.com.cn/rm...
该用什么办法呢?
刚看了自己的提问,没显示全,补充上图片,谢谢。
PHP中文网2017-04-18 10:26:39
The datetime module can generate time series and then concatenate strings.
If it is a crawler, the parameters in requests.get() in the Requests module can also be spliced.
Uh-huh. . . Allow me to tell you a dumber way.
I mainly do data analysis and visualization, and I am not a computer person. When I encounter problems, I first look for ready-made functions.
import datetime
from datetime import datetime as dt
startday = dt(2016, 1, 1)
ds = []
span = datetime.timedelta(1)
for i in range(365 * 2 + 1):
ds.append(startday)
startday += span
dss = [i.strftime('%Y-%m/%d') for i in ds]
rawurl = 'http://paper.people.com.cn/rmrb/html/'
url = [rawurl + i for i in dss]
阿神2017-04-18 10:26:39
Python method to get specific time in the past:
#!/usr/bin/python
import time
#取一天前的当前具体时间
time.strftime('%Y-%m-%d %T',time.localtime(time.time()-24*60*60))
#取15天前的当前具体时间
time.strftime('%Y-%m-%d %T',time.localtime(time.time()-15*24*60*60))
#取15天前当前具体时间的前2小时
time.strftime('%Y-%m-%d %T',time.localtime(time.time()-15*24*60*60-2*60*60))
Python method to get specific time in the future:
#!/usr/bin/python
import time
#取一天后的当前具体时间
time.strftime('%Y-%m-%d %T',time.localtime(time.time()+24*60*60))
#取20天后的当前具体时间
time.strftime('%Y-%m-%d %T',time.localtime(time.time()+20*24*60*60))
#取20天后当前具体时间的前2小时
time.strftime('%Y-%m-%d %T',time.localtime(time.time()+20*24*60*60-2*60*60))
For details, you can check out this Python time operation example and summary of time formatting parameters http://www.php.cn/python-tuto...