Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 18th, 2006, 7:14 PM   #1
nytrokiss
Newbie
 
Join Date: Oct 2006
Posts: 23
Rep Power: 0 nytrokiss is on a distinguished road
Angry RE working in the Interactive but not in script

I have a function
def next_page_finder(kite):
    site = urlopen(kite).read()
    next_site_pages = findall(r'\?Brand=\d+\&pg=\d+',site) #<--won't work in file 
    new_pages = []
when i call the re in the interactive interpreter it returns me a list however when i call in within my code it gives me a blank list?


:eek: :eek:
nytrokiss is offline   Reply With Quote
Old Nov 18th, 2006, 9:42 PM   #2
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Perhaps if you gave the URL it is failing on?
Arevos is offline   Reply With Quote
Old Nov 18th, 2006, 10:11 PM   #3
nytrokiss
Newbie
 
Join Date: Oct 2006
Posts: 23
Rep Power: 0 nytrokiss is on a distinguished road
http://www.goldwatches.com/watches.asp?Brand=11
nytrokiss is offline   Reply With Quote
Old Nov 18th, 2006, 10:50 PM   #4
Kaja Fumei
Hobbyist Programmer
 
Join Date: Oct 2005
Posts: 134
Rep Power: 4 Kaja Fumei is on a distinguished road
The regex is not supposed to match that URL. The regex only matches if "pg" is set by the URL. That URL doesn't do this but it would match this one: http://www.goldwatches.com/watches.asp?Brand=11&pg=0

If you want "pg" to be optional, change line 3 to:
next_site_pages = findall(r'\?Brand=\d+(\&pg=\d+)?',site)
Kaja Fumei is offline   Reply With Quote
Old Nov 18th, 2006, 11:16 PM   #5
nytrokiss
Newbie
 
Join Date: Oct 2006
Posts: 23
Rep Power: 0 nytrokiss is on a distinguished road
Quote:
Originally Posted by Kaja Fumei View Post
The regex is not supposed to match that URL. The regex only matches if "pg" is set by the URL. That URL doesn't do this but it would match this one: http://www.goldwatches.com/watches.asp?Brand=11&pg=0

If you want "pg" to be optional, change line 3 to:
next_site_pages = findall(r'\?Brand=\d+(\&pg=\d+)?',site)

I am not trying to match that url i am trying to pull a list out of it and now i will post screen shots!
Attached Images
File Type: jpg Problem_with_python1.jpg (61.7 KB, 49 views)
nytrokiss is offline   Reply With Quote
Old Nov 19th, 2006, 11:32 PM   #6
nytrokiss
Newbie
 
Join Date: Oct 2006
Posts: 23
Rep Power: 0 nytrokiss is on a distinguished road
any answer????
nytrokiss is offline   Reply With Quote
Old Nov 19th, 2006, 11:45 PM   #7
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 908
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
It would help if you posted all the code you are running (as text, not as an image). Then I could try it out for you and try to figure out what is wrong.
titaniumdecoy is offline   Reply With Quote
Old Nov 20th, 2006, 12:12 AM   #8
nytrokiss
Newbie
 
Join Date: Oct 2006
Posts: 23
Rep Power: 0 nytrokiss is on a distinguished road
Ok now that you see everything in diffrent steps i will show it in all and ones and please refer to the screen shot the code is
def next_page_finder(site):
    site = urlopen(site).read()
    next_site_pages = []
    next_site_pages.extend(findall(r'\?Brand=\d+\&pg=\d+',site))
    new_pages = []
    for _ in next_site_pages:
        new_pages.append(basejoin("http://www.goldwatches.com/watches.asp",_))
    return new_pages

The issue is that when i run the RE
next_site_pages.extend(findall(r'\?Brand=\d+\&pg=\d+',site))
it returns me an empty list however in the interactive input i run something akin to it
>>> from re import findall
>>> from urllib import basejoin,urlopen
>>> site = urlopen("http://www.goldwatches.com/watches.asp?Brand=11").read()
>>> findall(r'\?Brand=\d+\&pg=\d+',site)
Now as you see in the screen shot the interactive interpreter returns me a list of values however when i run it in regular python i get an empty list why??
nytrokiss is offline   Reply With Quote
Old Nov 20th, 2006, 12:27 AM   #9
nytrokiss
Newbie
 
Join Date: Oct 2006
Posts: 23
Rep Power: 0 nytrokiss is on a distinguished road
Might i add that the webpage it is failing on ( an example) is http://www.goldwatches.com/watches.asp?Brand=11 (posted above)
nytrokiss is offline   Reply With Quote
Old Nov 20th, 2006, 2:02 AM   #10
Game_Ender
Professional Programmer
 
Game_Ender's Avatar
 
Join Date: May 2006
Location: Maryland, USA
Posts: 306
Rep Power: 3 Game_Ender is on a distinguished road
I just tried the code, it work fine.
Game_Ender is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Backup Script :-) Pizentios Perl 18 Jan 12th, 2006 11:50 AM
A simple script isn't working correctly scuzzman Perl 3 Dec 23rd, 2005 7:42 AM
A simple perl script satimis Perl 3 Aug 15th, 2005 10:31 AM
Bash Script Help pelon Bash / Shell Scripting 2 Feb 28th, 2005 4:58 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:34 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC