In this article, I was able to get the time when scraping, so I would like to post a solution when I want to add the date and time to that time and convert it to datetime type.
Conversion from datetime to string
dt_now = dt.now()
time_str = dt_now.strftime('%Y/%m/%d')
This enables the following conversions. 2018-02-02 18:31:13→18/02/02 I think that you should combine the acquired value with this character string and then use strptime to convert it to datetime type.
** However, in my execution environment,% d inevitably causes an error, so I tried another method. ** **
Split datetime
dt_now = dt.now()
year = int(dt_now.year)
month = int(dt_now.month)
day = int(dt_now.day)
Combine these with the value obtained by scraping converted to int type.
datetime_after = dt(year,month,day,hour,minute)
The first step is to fix% d, but if it seems to fit, you may try Solution 2.
Recommended Posts