How to download a file from Google Webmaster Tools.
Introduction
This documentation explains how to automate the file download process from Google Webmaster Tools by using the python script downloader.py.
Details
The steps for running this example script are as follows:
- Download and install the Google Data APIs Python Client Library.
- Create a folder and add the downloader.py script to it.
- In the same folder where you added downloader.py, create and run the following Python script. You’ll need to replace the example values for “website”, “email” and “password” with valid values for your site.
#!/usr/bin/python
# Import the downloader
from downloader import Downloader
# Email address and password used to sign-in to Webmaster Tools
email = 'user@example.com'
password = '********'
# Specify the website and the type of data to download
website = 'http://www.example.com/'
selected_downloads = ['TOP_QUERIES']
# Instantiate the downloader object
downloader = Downloader()
# Authenticate with your Webmaster Tools sign-in info
downloader.LogIn(email, password)
# Initiate the download
downloader.DoDownload(website, selected_downloads)
Here is a more advanced example of how to automatically download a file, then upload it to Google Docs.
#!/usr/bin/python
# Import the downloader
from downloader import Downloader
# Import gdata objects for uploading files to Google Docs
import gdata.docs
import gdata.docs.service
# Email address and password used to sign-in to Webmaster Tools and Google Docs
email = 'user@example.com'
password = '********'
# Specify the website and the type of data to download
website = 'http://www.example.com/'
selected_downloads = ['TOP_QUERIES']
# Instantiate the downloader object
downloader = Downloader()
# Authenticate with your Webmaster Tools sign-in info
downloader.LogIn(email, password)
# Initiate the download
downloader.DoDownload(website, selected_downloads)
# Create a client class which will make HTTP requests with Google Docs server
gd_client = gdata.docs.service.DocsService()
# Authenticate using your Google Docs sign-in info
gd_client.ClientLogin(email, password)
# Get the csv file name that was generated by the downloader script and use it to upload the file to Google Docs
for line in downloader.GetDownloadedFiles():
ms = gdata.MediaSource(file_path=line.strip(), content_type=gdata.docs.service.SUPPORTED_FILETYPES['CSV'])
entry = gd_client.Upload(ms, line.strip())
# Display the URL of the uploaded file to the command line's standard-output
print 'Spreadsheet now accessible online at:', entry.GetAlternateLink().href
PR.registerLangHandler(PR.createSimpleLexer([["opn",/[\(\{\[]+/,o,"([{"],["clo",/[\)\}\]]+/,o,")]}"],[PR.PR_COMMENT,/;[\r\n]/,o,";"],[PR.PR_PLAIN,/[\t\n\r \xA0]+/,o,"\t\n\r \u00a0"],[PR.PR_STRING,/\"(?:[\"\\]|\\[\s\S])*(?:\"|$)/,o,'"']],[[PR.PR_KEYWORD,/(?:def|if|do|let|quote|var|fn|loop|recur|throw|try|monitor-enter|monitor-exit|defmacro|defn|defn-|macroexpand|macroexpand-1|for|doseq|dosync|dotimes|and|or|when|not|assert|doto|proxy|defstruct|first|rest|cons|defprotocol|deftype|defrecord|reify|defmulti|defmethod|meta|with-meta|ns|in-ns|create-ns|import|intern|refer|alias|namespace|resolve|ref|deref|refset|new|set!|memfn|to-array|into-array|aset|gen-class|reduce|map|filter|find|nil?|empty?|hash-map|hash-set|vec|vector|seq|flatten|reverse|assoc|dissoc|list|list?|disj|get|union|difference|intersection|extend|extend-type|extend-protocol|prn)\b/,