Python Forum

Full Version: NameError: name 'download' is not defined
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am trying to extract the country area from example website. And I got following errors. I am using python version 3.6
from bs4 import BeautifulSoup
url = 'http://example.webscraping.com/places/default/view/Australia-14'
html = download(url)
soup = BeautifulSoup(html)
# locate the area row
tr = soup.find(attrs={'id':'places_area_row'})
td = tr.find(attrs={'class':'w2p_fw'}) #locate the date elements
area = td.text #extract the text form the data element
print (area)
Error: "NameError: name 'download' is not defined"
This may be the place where to look.
where did you cause download to be defined?
Just remove download,and use Requests(is what should by used anyway in the download reference).
from bs4 import BeautifulSoup
import requests

url = 'http://example.webscraping.com/places/default/view/Australia-14'
url_get = requests.get(url)
soup = BeautifulSoup(url_get.content, 'html.parser')
contry = soup.find('tr', id="places_country__row")
print(contry.text)
Output:
Country: Australia