0

I'm using an example I found that extracts links from an webpage

from BeautifulSoup import BeautifulSoup
import urllib2
import re

html_page = urllib2.urlopen("http://arstechnica.com")
soup = BeautifulSoup(html_page)
for link in soup.findAll('a', attrs={'href': re.compile("^http://")}):
print link.get('href')

I get:

File "html_test.py", line 9
    print link.get('href')
             ^
SyntaxError: invalid syntax

I've installed BeautifulSoup with pip to no success.

OneCricketeer
  • 151,199
  • 17
  • 111
  • 216

1 Answers1

0

Instead of

from BeautifulSoup import BeautifulSoup

use:

from bs4 import BeautifulSoup

Also, in Python3, print is a function, not a statement:

print(link.get('href'))
OneCricketeer
  • 151,199
  • 17
  • 111
  • 216
Ajax1234
  • 66,333
  • 7
  • 57
  • 95