I would like to get the number within the nested tag. How would I do this?
My code outputs this, but I'd like to get the #40, not the whole two lines:
<span class="rankings-score">
<span>#40</span>
Here is my code:
from bs4 import BeautifulSoup
import requests
import csv
site = "http://www.usnews.com/education/best-high-schools/national-rankings/page+2"
fields = ['national_rank','school','address','school_page','medal','ratio','size_desc','students','teachers']
r = requests.get(site)
html_source = r.text
soup = BeautifulSoup(html_source)
table = soup.find('table')
rows_list = []
for row in table.find_all('tr'):
d = dict()
d['national_rank'] = row.find("span", 'rankings-score')
print d['national_rank']
I get this error:
AttributeError: 'NoneType' object has no attribute 'span'
when I try this:
d['national_rank'] = row.find("span", 'rankings-score').span.text