My web scraper is throwing NameError: name 'BeautifulSoup' is not defined
when I call BeautifulSoup() inside my function, but it works normally when I call it outside the function and pass the Soup as an argument.
Here is the working code:
from teams.models import *
from bs4 import BeautifulSoup
from django.conf import settings
import requests, os, string
soup = BeautifulSoup(open(os.path.join(settings.BASE_DIR, 'revolver.html')), 'html.parser')
def scrapeTeamPage(soup):
teamInfo = soup.find('div', 'profile_info')
...
print(scrapeTeamPage(soup))
But when I move the BeautifulSoup call inside my function, I get the error.
from teams.models import *
from bs4 import BeautifulSoup
from django.conf import settings
import requests, os, string
def scrapeTeamPage(url):
soup = BeautifulSoup(open(os.path.join(settings.BASE_DIR, url)), 'html.parser')
teamInfo = soup.find('div', 'profile_info')