Created
June 3, 2020 04:21
-
-
Save cjh0613/fb0daecee8b70de88c28802a3e72ede9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
import time | |
import datetime | |
import dateutil.parser | |
from bs4 import BeautifulSoup as bp | |
def get_(data): | |
headers={'User-Agent':'curl/7.12.1 ', | |
'Content-Type':'application/json'} | |
try: | |
r = requests.post(url='https://ssl.bing.com/webmaster/api.svc/json/SubmitUrl?apikey=APIKEY',json=data) | |
print(r.status_code) | |
print(r.content) | |
except Exception.e: | |
print(e) | |
print('start....','utf-8') | |
time.sleep(0.5) | |
site_url = 'https://cjh0613.github.io/blog/google-sitemap.xml' | |
try: | |
print('Get sitemap....','utf-8') | |
data_ = bp(requests.get(site_url).content,'lxml') | |
except Exception.e: | |
print(e) | |
list_url=[] | |
list_date=[] | |
print('---------------------------------') | |
#for x1,y1 in enumerate(data_.find_all('url')): | |
for x,y in enumerate(data_.find_all('loc')): | |
print(x,y.string) | |
list_url.append(y.string) | |
for x2,y2 in enumerate(data_.find_all('lastmod')): | |
startTime=y2.string | |
startTime=dateutil.parser.parse(startTime) | |
date1=(startTime.isoformat())[0:10] | |
startTime=date1+" "+(startTime.isoformat())[11:19] | |
startTime=datetime.datetime.strptime(startTime,"%Y-%m-%d %H:%M:%S") | |
now=datetime.datetime.utcnow() | |
endTime = datetime.datetime(now.year, now.month, now.day, now.hour, now.minute, now.second) | |
date2=(endTime.isoformat())[0:10] | |
date = endTime- startTime | |
seconds=date.seconds | |
if date1==date2 and seconds<600:#Can be modified | |
list_date.append(x2) | |
print('---------------------------------') | |
print(list_date) | |
print('submit....','utf-8') | |
for x in list_date: | |
cjhurl=list_url[x] | |
print('now:','utf-8' + cjhurl) | |
cjhpush={ | |
"siteUrl": "web",#Need modifing | |
"url": cjhurl | |
} | |
print(cjhpush) | |
get_(cjhpush) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment