我遇到了一些问题,我正在使用漂亮的汤剥离的html,只有文本。当我运行它的时候,我得到了错误,当我在我的divs变量中findAll的时候,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()?就在那里,只是为了得到文本,就像我有它一样?
我的代码:
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)发布于 2018-09-02 12:05:41
试试这个:
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编辑:
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列表
https://stackoverflow.com/questions/52133866
复制相似问题