Problem with spyder (interpreter)

12 views
Skip to first unread message

geoffroy...@gmail.com

unread,
Mar 4, 2018, 7:51:20 PM3/4/18
to beautifulsoup
hi, 

i've a problem with beautifulsoup and spyder. 

Spyder is my interpreter. 

My code is : 

from urllib.request import urlopen
from bs4 import BeautifulSoup 
html = urlopen(" https://www.legifrance.gouv.fr") 
bsObj = BeautifulSoup( html) 
for link in bsObj.findAll(" a"): 
       if 'href' in link.attrs:               
           print( link.attrs[' href'])

And the result is : 

runfile('/Users/geoffroy/Desktop/Ethereum/scrapy 4', wdir='/Users/geoffroy/Desktop/Ethereum')

There is no scrape. 

Do you know the matter ? 

Thank you for your help. 

Geoffroy. 

Jim Tittsler

unread,
Mar 5, 2018, 8:01:23 AM3/5/18
to beautifulsoup
On Mon, Mar 5, 2018 at 2:35 AM, <geoffroy...@gmail.com> wrote:
> from urllib.request import urlopen
> from bs4 import BeautifulSoup
> html = urlopen(" https://www.legifrance.gouv.fr")
> bsObj = BeautifulSoup( html)
> for link in bsObj.findAll(" a"):
> if 'href' in link.attrs:
> print( link.attrs[' href'])

I am not certain I understand your question. Or if your posting to
the list has changed how your code is rendered. But note that spacing
within strings is significant. Do you get your intended result if you
do:

> for link in bsObj.findAll("a"):
> if 'href' in link.attrs:
> print( link.attrs['href'])

(note the change in spacing for the tag and attribute name).
Reply all
Reply to author
Forward
0 new messages