Answer the question
In order to leave comments, you need to log in
How can I convert the date to the format I need?
Hello ! I am parsing the date of one page. And here is the result of parsing
2019-08-22T00:01:00Z
def get_data(html):
soup = BeautifulSoup(html, 'lxml')
item_datetime=soup.find('meta',{'itemprop':'dateCreated'})
item_datetime=dateparser.parse(item_datetime,date_formats=['%d %B %Y %H'])
print(item_datetime)
File "C:/Users/Administrator/PycharmProjects/Task/parsers/bnewskz/bnewskz_parser.py", line 13, in get_data item_datetime=dateparser.parse(item_datetime,date_formats=['%d %B %Y %H'])
raise TypeError('Input type must be str or unicode') TypeError: Input type must be str or unicode
Process finished with exit code 1
Answer the question
In order to leave comments, you need to log in
from dateutil import parser
item_datetime = parser.parse('2019-08-22T00:01:00Z')
soup.find returned the date already, most likely in date format. Just take it out the way you want it. And you're trying to parse it as a string. It is about this (that item_datetime is not a string) that is written to you in the error.
easy to check - insert print(type(item_datetime)) after soup.find
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question