-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdatedtime.py
28 lines (21 loc) · 1005 Bytes
/
updatedtime.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import json
import requests
url = "https://www.economist.com/the-world-in-brief"
response = requests.get(url)
if response.status_code == 200:
start_index = response.text.find('<script type="application/ld+json">') + len('<script type="application/ld+json">')
end_index = response.text.find('</script>', start_index)
json_data = response.text[start_index:end_index].strip()
data = json.loads(json_data)
date_published = data.get("datePublished", "")
date_modified = data.get("dateModified", "")
print("Date Published:", date_published)
print("Date Modified:", date_modified)
with open("DatePublished.txt", "w") as file_published:
file_published.write(date_published)
with open("DateModified.txt", "w") as file_modified:
file_modified.write(date_modified)
print("Date Published saved to 'DatePublished.txt'")
print("Date Modified saved to 'DateModified.txt'")
else:
print("Failed to fetch data. Status code:", response.status_code)