HELP! Return URLs in redirect chain

Reply

Join Date: Nov 2009
Posts: 1
Reputation: LB22 is an unknown quantity at this point 
Solved Threads: 0
LB22 LB22 is offline Offline
Newbie Poster

HELP! Return URLs in redirect chain

 
0
  #1
21 Days Ago
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. 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
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 77
Reputation: pythopian is an unknown quantity at this point 
Solved Threads: 18
pythopian pythopian is offline Offline
Junior Poster in Training

Use a generator function/method

 
0
  #2
14 Days Ago
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:
  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
"I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum."
------------
This posts may be redistributed under the Creative Commons BY-SA License.
Reply With Quote Quick reply to this message  
Reply

Tags
python, redirect, url, urllib2

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC