Order it now! Amazon prioritizes orders on a first come, first served basis.


View Full Version : Print Version


Neels
10-04-2009, 03:33 PM
Greetings,

Please have some patience as I'm not a python/web/html/soup developer :)

I am trying to return the print version of an article from an rss feed. The url looks something like this:

http://www.news24.com/Content/SouthAfrica/News/1059/1cfd873e535e4b5ab944da15f15aff46/04-10-2009%2008-08/CT_faces_huge_maintenance_bill

The print version url looks like this:

http://www.news24.com/printArticle.aspx?iframe&aid=1cfd873e-535e-4b5a-b944-da15f15aff46&cid=1059

The problem is that the print url is supplied through a java script:
<script language="JavaScript">
function openPrintWindow() {
myPrintWindow = window.open('http://www.news24.com/printArticle.aspx?iframe&aid=1cfd873e-535e-4b5a-b944-da15f15aff46&cid=1059','myPrintWindow','toolbar=0,location=0,di rectories=0,status=0,menubar=0,scrollbars=1,resiza ble=0,width=750,height=600');
}
</script>

So, what is the easiest way to grab that URL from the java script? I've looked at some of the builtin recipes but could not find anything that relates to a specific case like this. Or maybe I just didn't understand the python code ;)

Any help appreciated.
Regards,
Neels

kovidgoyal
10-04-2009, 03:54 PM
use a regular expression to match the text in the javascript.

Neels
10-04-2009, 11:26 PM
Ok,

A little example:
Q: How do I travel from Z to Y?
A: Use an automobile.

Not to belittle the regular expression answer, but .... uhhmmmm HOW? Does anyone have some sample code using regular expressions?

Regards,
Neels

kovidgoyal
10-05-2009, 01:39 PM
is the javascript in the feed file or in the html linked to by the rss feed?

kiklop74
10-05-2009, 07:53 PM
This is what you should use:


def print_version(self, url):
artl = url.rpartition('/')[0]
artl2 = artl.rpartition('/')[0]
rrest, sep, aid= artl3.rpartition('/')
cid = rrest.rpartition('/')[2]
return 'http://www.news24.com/printArticle.aspx?iframe&aid=' + aid + '&cid=' + cid

Neels
10-12-2009, 03:09 PM
Thanks!! Will try that tonight. Much appreciated.

<edit>

PERFECT. I will study it a bit as there is another site using a similar method and post both recipes when done.

Thanks again.