0

Hi,

I'm stuck with a certain problem. I'm using URLLIB2 to get the end url of a list of links. This was pretty straightforward. Some of the links I'm probing pass through 1 or more other urls before landing the user at the end destination.

For example, the start url might be 1, but then you only end up at 3 after a quick and probably unnoticeable redirect to 2:

1. http://click.someurl.net/script?query=somedata
2. http://bridge.url.net/redirect?url=http://thenewurl.com
3. http://thenewurl.com

In my code url 1 is passed to my function, and url 3 is returned, but how do I capture/return any URL in between the start and end points?

Thanks in advance for any help!

LB

2
Contributors
1
Reply
3
Views
7 Years
Discussion Span
Last Post by pythopian
0

Your post does not provide many details, but I think what you are looking for is a generator function., Instead of returning an URL, yield each URL, like this:

def generateURLs(startingURL):
    url = startingURL
    ...
    while url:
        yield url
        url = getNextURL(url)
...
for url in generateURLs(http://click.someurl.net/script?query=somedata):
    print url
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.