Creating a Super Simple WWW Link, Copy, & Paste into Spreadsheet Program

Dave Angel davea at davea.name
Thu Jun 13 16:08:38 EDT 2013


On 06/13/2013 03:28 PM, buford.lumbar at gmail.com wrote:
> Hi, I'm new to Python. Would someone be able to write me and/or to show me how to write a simple program that:

Hi, welcome to Python, and to the Python-list

It's NOT a simple program, except by a very constrained definition of 
simple.

>
> 1-follows a hyperlink from MS Excel to the internet (one of many links like this, http://www.zipdatamaps.com/76180, for e.g.) and then,
>
> 2-copies some data (a population number, e.g. 54195) and then,
>
> 3-pastes that data back into the same MS Excel spreadsheet, into the adjacent cell.
>
> ... and that’s it... row after row of hyperlinks all in one column...


What's the real problem, or is it assignment?  Do you have lots of 
repetitive data you want to fetch once a day from many websites?  Do you 
have an assignment that constrains you to use Excel and Windows, and 
Python?  Do you have a boss that likes innovation?  Are you supposed to 
fetch the links from a live instance of Excel ?

What version of Python, and what OS does this have to run on?

If you break the problem into its component parts, SOME of them are 
fairly simple.  If you try to solve the problem as a whole, it's not 
simple, unless you can just copy much of it from your textbook, or from 
earlier assignments.

If this were my problem, I'd throw out Excel to begin with.  If your 
hyperlinks happen to be in an excel spreadsheet, then export them, 
probably to a csv file.  Do that by hand.  If it later proves valuable 
to automate that, consider it a new problem.  Similarly getting the data 
back into Excel -- just use csv files.

So now you have a URL, and you want to get something from the web.  You 
could use one of the urlib libraries to fetch the page.  You're pretty 
vague about "some data" but you could use substring to extract some 
bytes from the page.

You can use the csv module to load in the spreadsheet, and iterate 
through the rows.  For each row, you could use the previous paragraph to 
convert the URL into some data.  Then write the row back out, but to a 
different csv file.

If you want anything more specific than that (and probably not from me), 
you'd have to get a lot more specific about your real requirements.  And 
convince somebody that it's not homework.

-- 
DaveA



More information about the Python-list mailing list