python - Append hrefs into list using Beautiful Soup -


using beautiful soup, trying append links on site list following code. however, code seems iterate through link list , add 15 times code iterates through link list on site, output not expected. have advice how adjust code each link appended once? in end, i'd have list containing 15 links. thanks.

from bs4 import beautifulsoup import urllib2 url = 'http://www.gks.ru/bgd/free/b00_25/isswww.exe/stg/d000/i000650r.htm' data = urllib2.urlopen(url).read() page = beautifulsoup(data,'html.parser') l=[] link in page.findall('a'):        l.append(link.get('href'))        print l[0:] 

based on discussion in comments, appears error include print statement in loop. wanted print of links once @ end, code should be:

l=[] link in page.findall('a'):     l.append(link.get('href')) print l 

note need print l. l[0:] equivalent.


Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -