У меня проблемы с использованием Beautifulsoup, чтобы убрать HTML и получить только текст. Когда я запускаю его, я получаю сообщение об ошибке AttributeError: ResultSet object has no attribute 'get_text'. You're probably treating a list of items like a single item. Did you call find_all() when you meant to call find()? Есть ли способ просто получить текст, когда я findAll в моей переменной divs, как у меня?
AttributeError: ResultSet object has no attribute 'get_text'. You're probably treating a list of items like a single item. Did you call find_all() when you meant to call find()?
findAll
divs
Мой код:
import requests from bs4 import BeautifulSoup url = 'https://www.brightscope.com/form-5500/basic-info/107299/Orthopedic-Institute-Of-Pennsylvania/15801790/Orthopedic-Institute-Of-Pennsylvania-401k-Profit-Sharing-Plan/' page = requests.get(url) soup = BeautifulSoup(page.text, 'html.parser') divs = soup.findAll('span', class_='float-right').get_text() for each in divs: print(each)
Попробуйте это:
import requests from bs4 import BeautifulSoup url = 'https://www.brightscope.com/form-5500/basic-info/107299/Orthopedic-Institute-Of-Pennsylvania/15801790/Orthopedic-Institute-Of-Pennsylvania-401k-Profit-Sharing-Plan/' page = requests.get(url) soup = BeautifulSoup(page.text, 'html.parser') divs = soup.findAll('span', class_='float-right') #not on the collection of elements for each in divs: print(each.get_text()) #get_text goes here on the element
EDIT:
import requests from bs4 import BeautifulSoup url = 'https://www.brightscope.com/form-5500/basic-info/107299/Orthopedic-Institute-Of-Pennsylvania/15801790/Orthopedic-Institute-Of-Pennsylvania-401k-Profit-Sharing-Plan/' page = requests.get(url) soup = BeautifulSoup(page.text, 'html.parser') divs = [e.get_text() for e in soup.findAll('span', class_='float-right')]
Получит вам список div в формате строки