Skip to content

Instantly share code, notes, and snippets.

@sekimura
Last active December 18, 2015 18:19
Show Gist options
  • Save sekimura/5825143 to your computer and use it in GitHub Desktop.
Save sekimura/5825143 to your computer and use it in GitHub Desktop.
import sys
import urllib2
import xml.etree.ElementTree as ET
PING_URL = 'http://www.google.com/webmasters/tools/ping?sitemap=%s'
def fetch_sitemaps(sitemapindex):
response = urllib2.urlopen(sitemapindex)
xml = response.read()
root = ET.fromstring(xml)
for loc in root.getiterator('{http://www.sitemaps.org/schemas/sitemap/0.9}loc'):
yield loc.text
def resubmit(sitemap):
url = PING_URL % sitemap
response = urllib2.urlopen(url)
print response.read()
if __name__ == '__main__':
for sitemap in fetch_sitemaps(sys.argv[1]):
resubmit(sitemap)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment