Reputation: 9338
I am learning the BeautifulSoup 4 Documentation, and want to exercise the examples given.
I am trying the examples however it’s not successful. An example below.
It seems I am not putting it in the right way, and problem lies in the ‘url’. What is the right way to put them?
from bs4 import BeautifulSoup
import re
import urllib2
url = '<a class="sister" href="http://example.com/elsie" id="link1">Elsie</a>'
page = urllib2.urlopen(url)
soup = BeautifulSoup(page.read())
Learning = soup.find_all("a", class_="sister")
print Learning
Upvotes: 2
Views: 6262
Reputation: 368894
'<a class="sister" href="http://example.com/elsie" id="link1">Elsie</a>'
is not an url.
The code contains html; You don't need to use urllib2.urlopen
.
from bs4 import BeautifulSoup
page = '<a class="sister" href="http://example.com/elsie" id="link1">Elsie</a>'
soup = BeautifulSoup(page)
Learning = soup.find_all("a", class_="sister")
print Learning
Upvotes: 2