Please support our Python advertiser: Programming Forums
Views: 3384 | Replies: 6
![]() |
•
•
Join Date: Jul 2005
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 0
Hello,
This is my first python script, so I could use a little bit of help here.
I'm using the 'Universal Feed Parser' (http://feedparser.org/), and I have a list of feed URLs in a database which I would like to pull out and go through each of them. I am also using the ADOdb database module, as I am familier with it (in PHP .. however, it is pretty similar ..)
Here's what I have so far, the only thing this does is pulls the URLs out of the database, and prints them:
As I said, this above code works perfectly. However, I want to take that output, and put it in something like this:
So, basically .. the above code is calling a function from the 'Universal Feed Parser' module, which takes in a url .. basically, when it executes, I want python to read it like this:
I know it has got to be something simple. I'd definitely appreciate some help on this. Thank you very much
This is my first python script, so I could use a little bit of help here.

I'm using the 'Universal Feed Parser' (http://feedparser.org/), and I have a list of feed URLs in a database which I would like to pull out and go through each of them. I am also using the ADOdb database module, as I am familier with it (in PHP .. however, it is pretty similar ..)
Here's what I have so far, the only thing this does is pulls the URLs out of the database, and prints them:
#!/usr/bin/env python
import MySQLdb
import adodb
import feedparser
conn = adodb.NewADOConnection('mysql')
conn.Connect('localhost','root','dadada','db');
cursor = conn.Execute('SELECT feed_url FROM feed_urls')
while not cursor.EOF:
for row in cursor.fields:
print row
cursor.MoveNext()
cursor.Close()
conn.Close()As I said, this above code works perfectly. However, I want to take that output, and put it in something like this:
while not cursor.EOF:
for row in cursor.fields:
d = feedparser.parse(FEED_URL_HERE) <-- This is where I need the output of the db results to appearSo, basically .. the above code is calling a function from the 'Universal Feed Parser' module, which takes in a url .. basically, when it executes, I want python to read it like this:
d = feedparser.parse('http://www.url.com/to/rss.feed')I know it has got to be something simple. I'd definitely appreciate some help on this. Thank you very much
•
•
Join Date: May 2005
Posts: 215
Reputation:
Rep Power: 4
Solved Threads: 0
forgive me if I am saying something dumb, but is the output you need being produced by this code
if so what part of that code is producing the output?
#!/usr/bin/env python
import MySQLdb
import adodb
import feedparser
conn = adodb.NewADOConnection('mysql')
conn.Connect('localhost','root','dadada','db');
cursor = conn.Execute('SELECT feed_url FROM feed_urls')
while not cursor.EOF:
for row in cursor.fields:
print row
cursor.MoveNext()
cursor.Close()
conn.Close()if so what part of that code is producing the output?
•
•
Join Date: Jul 2005
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 0
Yes, this snippet actually works. The output is being produced with this line:
'row' is the variable holding the data.
I've tried just doing this:
..however, that doesn't work.
print row
'row' is the variable holding the data.
I've tried just doing this:
while not cursor.EOF:
for row in cursor.fields:
d = feedparser.parse(row) <-- This is the variable (row)..however, that doesn't work.
•
•
•
•
Originally Posted by shanenin
forgive me if I am saying something dumb, but is the output you need being produced by this code
#!/usr/bin/env python import MySQLdb import adodb import feedparser conn = adodb.NewADOConnection('mysql') conn.Connect('localhost','root','dadada','db'); cursor = conn.Execute('SELECT feed_url FROM feed_urls') while not cursor.EOF: for row in cursor.fields: print row cursor.MoveNext() cursor.Close() conn.Close()
if so what part of that code is producing the output?
•
•
Join Date: May 2005
Posts: 215
Reputation:
Rep Power: 4
Solved Threads: 0
I am pretty new to python(and programming) but this might work
now you should be able to place the varialble url in your function. but the variable url will be changed everytime you loop.
edit adeed later//
Sorry I should have tested that before I posted, I doesn't seem to work the way I thought it would :-(
while not cursor.EOF:
for row in cursor.fields:
url = row
print row
cursor.MoveNext()edit adeed later//
Sorry I should have tested that before I posted, I doesn't seem to work the way I thought it would :-(
•
•
Join Date: Jul 2005
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 0
Hi there,
Thanks for your replies.
The repr function seems to be useful.. Here's my exact problem though:
If you see the line d = feedparser.parse(str1), I believe this is where the error is occuring. If I simply do print str1, it prints the variable. I just need the variable to be accessable within the feedparser.parse function.
Here's the error I get with the above code:
I believe that it is simply not able to access the url contained in the variable (hence the no 'title' attribute)..
Any ideas? This has been bugging me for quite a while...
Again, thank you for your time!
Thanks for your replies.
The repr function seems to be useful.. Here's my exact problem though:
while not cursor.EOF:
for row in cursor.fields:
str1 = repr(row)
#print str1 #this line works .. if I take out the code below from above cursor.MoveNext()
d = feedparser.parse(str1)
d.feed.title
print d.feed.title
print "-----------------------------"
cursor.MoveNext()If you see the line d = feedparser.parse(str1), I believe this is where the error is occuring. If I simply do print str1, it prints the variable. I just need the variable to be accessable within the feedparser.parse function.
Here's the error I get with the above code:
[root@localhost feedparser]# ./parse.py
Traceback (most recent call last):
File "./parse.py", line 17, in ?
d.feed.title
File "/home/matt/feedparser/feedparser.py", line 184, in __getattr__
raise AttributeError, "object has no attribute '%s'" % key
AttributeError: object has no attribute 'title'I believe that it is simply not able to access the url contained in the variable (hence the no 'title' attribute)..
Any ideas? This has been bugging me for quite a while...
Again, thank you for your time! ![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)






Linear Mode