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
  • 179,855
  • 19
  • 132
  • 245

1 Answers1

1

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
  • 179,855
  • 19
  • 132
  • 245
Ajax1234
  • 69,937
  • 8
  • 61
  • 102