Reputation: 57
I want to scrape the text of each li
in ul
with class="academicsList"
from the following page:
I am getting the error: navigateable string has no attribute text
. What is causing this problem and how can I resolve it?
Here is my code
import requests
from bs4 import BeautifulSoup
from fake_useragent
import UserAgent
ua = UserAgent()
header = {'user-agent':ua.chrome}
response = requests.get('https://www.eduvision.edu.pk/institutions-detail.php?city=51I&institute=3149_federal-urdu-university-of-arts-science-technology-islamabad',headers=header)
soup = BeautifulSoup(response.content, 'html.parser')
disciplines = soup.findAll("ul", {"class": "academicsList"})
for d in disciplines:
for li in d:
print(li.text)
print("...............")
Upvotes: 1
Views: 2395
Reputation: 1402
Welcome to SO!
You are trying to iterate the ul tag you found. But you are supposed to iterate the li tags. For that you need to add .findAll('li')
in d. Like,
for d in disciplines:
for li in d.findAll('li'):
print(li.text)
print("...............")
Hope this helps! Cheers!
Upvotes: 1