Question

I have some code saved in a .py file, which, for a given URL, will return the Google page ranking of the URL.

So on command line I will run : 

python GetRanking.py www.google.com

and output :

Traffic stats for: www.google.com
AlexaTrafficRank:1
GooglePageRank:9

Now, I have a .tsv file of URLs.

I would like to create a new .py file, which, for each URL, will calculate the page ranking and alexa traffic rank using GetRanking.py, and append it to the row in the .tsv file.

Currently my .tsv looks like :

url   PageRank   AlexaRank
www.google.com
www.foo.com
http://www.test.com
http://www.stackoverflow.com

The end result I want is (using dummy values, the values I want are the ones produced by the GetRanking.py file above :

url   PageRank   AlexaRank
www.google.com   9   1
www.foo.com   177   43432
http://www.test.com   2132   4567
http://www.stackoverflow.com   8   9
Was it helpful?

Solution

if you want to save an output of a .py file to a csv file. You can always use csv lib.

I suppose your output can be store into a 2 dimensional list:

import csv
ls = [['www.google.com','9','1'],['www.foo.com','177','43432'],['http://www.test.com','2132','4567'],['http://www.stackoverflow.com','8','9']]
file = open('test.csv', 'w');
writer = csv.writer(file)
for item in ls:
    writer.writerow(item)
file.close()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top