Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #68769

Re: help with for loop----python 2.7.2

References <84eb4c69-d43d-4777-8a99-34eed9be73d6@googlegroups.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2014-03-22 06:00 -0600
Subject Re: help with for loop----python 2.7.2
Newsgroups comp.lang.python
Message-ID <mailman.8394.1395489716.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Sat, Mar 22, 2014 at 5:21 AM,  <teddybubu@gmail.com> 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....

[SNIP]

> 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

The three find method calls in the for loop are searching from the
document root (the "soup" variable), not from the item you're
currently iterating at.  Try changing these to calls of item.find. And
note that calling one of the results "item" will replace the loop
variable.  That won't affect the iteration, but it's bad practice to
refer to two different things by the same local name.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

help with for loop----python 2.7.2 teddybubu@gmail.com - 2014-03-22 04:21 -0700
  Re: help with for loop----python 2.7.2 Ian Kelly <ian.g.kelly@gmail.com> - 2014-03-22 06:00 -0600
  Re: help with for loop----python 2.7.2 tad na <teddybubu@gmail.com> - 2014-03-23 10:29 -0700
    Re: help with for loop----python 2.7.2 tad na <teddybubu@gmail.com> - 2014-03-23 10:30 -0700
      Re: help with for loop----python 2.7.2 Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-03-23 17:40 +0000
        Re: help with for loop----python 2.7.2 tad na <teddybubu@gmail.com> - 2014-03-23 10:49 -0700
      Re: help with for loop----python 2.7.2 Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-03-23 18:43 +0000
    Re: help with for loop----python 2.7.2 Ian Kelly <ian.g.kelly@gmail.com> - 2014-03-23 11:49 -0600
      Re: help with for loop----python 2.7.2 tad na <teddybubu@gmail.com> - 2014-03-23 14:51 -0700
        Re: help with for loop----python 2.7.2 Ian Kelly <ian.g.kelly@gmail.com> - 2014-03-23 16:44 -0600
  Re: help with for loop----python 2.7.2 Ben Finney <ben+python@benfinney.id.au> - 2014-03-24 09:39 +1100

csiph-web