Re: help with for loop----python 2.7.2
On Saturday, March 22, 2014 6:21:30 AM UTC-5, tad na wrote: > I am trying to get all the element data from the rss below. > > The only thing I am pulling is the first element. > I don't understand why the for loop does not go through the entire rss. > Here is my code > try: > from urllib2 import urlopen > except ImportError: > from urllib.request import urlopen > from bs4 import BeautifulSoup > soup = BeautifulSoup(urlopen('http://bl.ocks.org/mbostock.rss')) > #print soup.find_all('item') > #print (soup) > for item in soup.find_all('item'): > #for item in soup: > title = soup.find('title').text > link = soup.find('link').text > item = soup.find('item').text > print item > print title > print link OK . second problem :) I can print the date. not sure how to do this one.. try: from urllib2 import urlopen except ImportError: from urllib.request import urlopen import urllib2 from bs4 import BeautifulSoup soup = BeautifulSoup(urlopen('http://bl.ocks.org/mbostock.rss')) #print soup.find_all('item') #print (soup) data = soup.find_all("item") x=0 for item in soup.find_all('item'): title = item.find('title').text link = item.find('link').text date = item.find('pubDate') # print date print('+') print data[x].title.text print data[x].link.text print data[x].guid.text print data[x].pubDate x = x + 1 -- https://mail.python.org/mailman/listinfo/python-list
Re: python installation on windows
On Sunday, March 23, 2014 12:09:09 PM UTC-5, rbor...@gmail.com wrote: > Hi Everybody > > > > actually i want to run python on web browser. I downloaded python and > installed but i'm not able to run it in browser but it running using command > prompt. so i trying to install mod_wsgi 3.4. So i downloaded precompiled > version mod_wsgi-3.4.ap22.win32-py2.6 and copied mod_wsgi.so file to > C:\wamp\bin\apache\Apache2.2.11\modules after i'm trying to run .\configure > on path C:\Documents and Settings\Rahul\Desktop\mod_wsgi-3.4.ap22.win32-py2.6 > but it giving me error that .\configure is not recognized as internal or > external command. > > > > So please suggest me what can i do for that, i'm so beginner to python and > installing and configuring modules for apache. > > > > Thanks > > Rahul To set up a web browser: 1.open a dos window 2.navigate to dir you want "served" 3.type "python -m SimpleHTTPServer &." -- https://mail.python.org/mailman/listinfo/python-list
Re: help with for loop----python 2.7.2
On Sunday, March 23, 2014 12:29:40 PM UTC-5, tad na wrote: > On Saturday, March 22, 2014 6:21:30 AM UTC-5, tad na wrote: > > > I am trying to get all the element data from the rss below. > > > > > > The only thing I am pulling is the first element. > > > > > I don't understand why the for loop does not go through the entire rss. > > > > > Here is my code > > > try: > > > from urllib2 import urlopen > > > except ImportError: > > > from urllib.request import urlopen > > > from bs4 import BeautifulSoup > > > soup = BeautifulSoup(urlopen('http://bl.ocks.org/mbostock.rss')) > > > #print soup.find_all('item') > > > #print (soup) > > > for item in soup.find_all('item'): > > > #for item in soup: > > > title = soup.find('title').text > > > link = soup.find('link').text > > > item = soup.find('item').text > > > print item > > > print title > > > print link > > OK . second problem :) > > I can print the date. not sure how to do this one.. > > try: > > from urllib2 import urlopen > > except ImportError: > > from urllib.request import urlopen > > import urllib2 > > from bs4 import BeautifulSoup > > > > soup = BeautifulSoup(urlopen('http://bl.ocks.org/mbostock.rss')) > > #print soup.find_all('item') > > #print (soup) > > data = soup.find_all("item") > > > > x=0 > > for item in soup.find_all('item'): > > title = item.find('title').text > > link = item.find('link').text > > date = item.find('pubDate') > ># print date > > print('+') > > print data[x].title.text > > print data[x].link.text > > print data[x].guid.text > > print data[x].pubDate > > x = x + 1 meant to say CANNOT print the date -- https://mail.python.org/mailman/listinfo/python-list
Re: help with for loop----python 2.7.2
On Sunday, March 23, 2014 12:40:04 PM UTC-5, Mark Lawrence wrote: > On 23/03/2014 17:30, tad na wrote: > Would you please use the mailing list > https://mail.python.org/mailman/listinfo/python-list or read and action > this https://wiki.python.org/moin/GoogleGroupsPython to prevent us > seeing double line spacing and single line paragraphs, thanks. > -- > My fellow Pythonistas, ask not what our language can do for you, ask > what you can do for our language. > Mark Lawrence > --- > This email is free from viruses and malware because avast! Antivirus > protection is active. > http://www.avast.com mark not sure what i did wrong. The double line in the code is mine. it helps me keep things separate. -- https://mail.python.org/mailman/listinfo/python-list
Re: python installation on windows
On Sunday, March 23, 2014 12:33:02 PM UTC-5, tad na wrote: > On Sunday, March 23, 2014 12:09:09 PM UTC-5, rbor...@gmail.com wrote: > > Hi Everybody > > actually i want to run python on web browser. I downloaded python and > > installed but i'm not able to run it in browser but it running using > > command prompt. so i trying to install mod_wsgi 3.4. So i downloaded > > precompiled version mod_wsgi-3.4.ap22.win32-py2.6 and copied mod_wsgi.so > > file to C:\wamp\bin\apache\Apache2.2.11\modules after i'm trying to run > > .\configure on path C:\Documents and > > Settings\Rahul\Desktop\mod_wsgi-3.4.ap22.win32-py2.6 but it giving me error > > that .\configure is not recognized as internal or external command. > > So please suggest me what can i do for that, i'm so beginner to python and > > installing and configuring modules for apache. > > Thanks > > Rahul > To set up a web browser: > 1.open a dos window > 2.navigate to dir you want "served" > 3.type "python -m SimpleHTTPServer &." 4. open browser and type http://localhost:/ -- https://mail.python.org/mailman/listinfo/python-list
Re: help with for loop----python 2.7.2
On Sunday, March 23, 2014 12:49:11 PM UTC-5, Ian wrote: > On Mar 23, 2014 11:31 AM, "tad na" wrote: > > OK . second problem :) > > I can print the date. not sure how to do this one.. > Why not? What happens when you try? > > try: > > from urllib2 import urlopen > > except ImportError: > > from urllib.request import urlopen > > import urllib2 > > from bs4 import BeautifulSoup > > soup = BeautifulSoup(urlopen('http://bl.ocks.org/mbostock.rss')) > > #print soup.find_all('item') > > #print (soup) > > data = soup.find_all("item") > > x=0 > > for item in soup.find_all('item'): > > title = item.find('title').text > > link = item.find('link').text > > date = item.find('pubDate') > > # print date > > print('+') > > print data[x].title.text > > print data[x].link.text > > print data[x].guid.text > > print data[x].pubDate > > x = x + 1 > data[x] should be the same object as item, no? If you want to keep track of > the current iteration index, a cleaner way to do that is by using enumerate: > for x, item in enumerate(soup.find_all('item')): > As far as printing the pubDate goes, why not start by getting its text > property as you do with the other tags? From there you can either print the > string out directly or parse it into a datetime object. This is the error I get with 1. print data[x].pubDate.text AttributeError: 'NoneType' object has no attribute 'text' 2. print data[x].pubDate It results in "None" -- https://mail.python.org/mailman/listinfo/python-list
feedparser error
python 2.7.2 The following code has an error and I can not figure out why: import feedparser d = feedparser.parse('http://bl.ocks.org/mbostock.rss') numb = len(d['entries']) for post in d.entries: print post.pubDate+"\n" --- the error is : print post.pubDate+"\n" File "build\bdist.win32\egg\feedparser.py", line 416, in __getattr__ raise AttributeError, "object has no attribute '%s'" % key AttributeError: object has no attribute 'pubDate' --- The only thing I can think of is feedparser does not like uppercase(pubDate)? I can not change someone else's rss. What can I do here? -- https://mail.python.org/mailman/listinfo/python-list
Re: feedparser error
You guys are good. thanks. === On Saturday, April 26, 2014 11:55:35 AM UTC-5, MRAB wrote: On 2014-04-26 03:16, tad na wrote: python 2.7.2 The following code has an error and I can not figure out why: import feedparser d = feedparser.parse('http://bl.ocks.org/mbostock.rss') numb = len(d['entries']) for post in d.entries: print post.pubDate+"\n" --- the error is : print post.pubDate+"\n" File "build\bdist.win32\egg\feedparser.py", line 416, in __getattr__ raise AttributeError, "object has no attribute '%s'" % key AttributeError: object has no attribute 'pubDate' --- The only thing I can think of is feedparser does not like uppercase(pubDate)? I can not change someone else's rss. What can I do here? Print dir(post) to see what attributes it has. -- https://mail.python.org/mailman/listinfo/python-list