Reputation:
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.
Upvotes: 0
Views: 3343
Reputation: 71451
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'))
Upvotes: 1