python - Get text from <a> element? -


i school name, "perkins college..." link using beautifulsoup.

the code use returns nothing.

school = soup.find('a','profiles-show-school-name-sm-link') print 'school: ', school print 'school.text: ', school.text 

output:

school:  <a class="profiles-show-school-name-sm-link" href="/profiles/show/online-degrees/stephen-f-austin-state-university/perkins-college-of-education-undergraduate/395/5401"> <img border="0" src="/images/profiles/243x60/4613/degrees/undergraduate-certificate-in-hospitality-administration.png"/> </a> school.text:   

suggestions beautifulsoup implementation extract school name (not url)? thx!

school = soup.find('a','profiles-show-school-name-sm-link') url = school['href'] 

assuming school in same spot in url:

for in range(5):    url = url[url.find("/")+1:] schoolname = url[:url.find("/")] print " ".join(schoolname.split("-")).title() 

yields:

perkins college of education undergraduate 

getting university

for in range(4):    url = url[url.find("/")+1:] university= url[:url.find("/")] print " ".join(university.split("-")).title() 

yields:

stephen f austin state university 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -