944,082 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 1914
  • Python RSS
Nov 4th, 2009
0

HELP! Return URLs in redirect chain

Expand Post »
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:

Python Syntax (Toggle Plain Text)
  1. 1. http://click.someurl.net/script?query=somedata
  2. 2. http://bridge.url.net/redirect?url=http://thenewurl.com
  3. 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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
LB22 is offline Offline
1 posts
since Nov 2009
Nov 11th, 2009
0

Use a generator function/method

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:
Python Syntax (Toggle Plain Text)
  1. def generateURLs(startingURL):
  2. url = startingURL
  3. ...
  4. while url:
  5. yield url
  6. url = getNextURL(url)
  7. ...
  8. for url in generateURLs(http://click.someurl.net/script?query=somedata):
  9. print url
Reputation Points: 20
Solved Threads: 25
Junior Poster in Training
pythopian is offline Offline
81 posts
since Nov 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Tasparent window inside a visible frame
Next Thread in Python Forum Timeline: A newbie question of sorts





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC