| | |
HELP! Return URLs in redirect chain
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2009
Posts: 1
Reputation:
Solved Threads: 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:
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
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. 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
•
•
Join Date: Nov 2009
Posts: 79
Reputation:
Solved Threads: 22
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)
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
"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.
------------
This posts may be redistributed under the Creative Commons BY-SA License.
![]() |
Similar Threads
- I want google to index forum threads (Search Engine Optimization)
- Buy Targeted Traffic, higher ROI (Ad Space for Sale)
- Take part of URL, put into form, post to database. (PHP)
- Complete Makeover - Fear Of Losing Ranking (Search Engine Optimization)
- Page Redirection error (PHP)
- redirect to same filename without extension (Linux Servers and Apache)
- vBulletin mod_rewrite (PHP)
- Need Help (C)
Other Threads in the Python Forum
- Previous Thread: Tasparent window inside a visible frame
- Next Thread: A newbie question of sorts
| Thread Tools | Search this Thread |
301 abrupt advice adware aliased arax background bash beginner bmp book broken c# c++ code console coordinates corners cron cturtle curves data def development django domain duplicate dynamic edit editing enter event examples excel file function generator google gui halp htaccess ideas iframe infosec input ip jaunty java jsp keyboard line link linux list lists loan microsoft module movingimageswithpygame mysql numbers parameters programming projects py2exe pygame pygtk python random read redirect redirecting response return ruby simple source sqlite string sudokusolver table terminal thread threading tkinter tlapse tutorial ubuntu update url urllib urllib2 variable voip web wikipedia wordgame write wxpython xlwt






