使用python的beautifulsoup库爬取网页数据的时候,使用select方法找标签并赋值,get_text()提取文本内容时,报错:

AttributeError: ResultSet object has no attribute 'get_text'. You're probably treating a list of elements like a single element. Did you call find_all() when you meant to call find()?

原来代码如下:

date = i.select('.c-abstract')
dict['date'].append(''.join(date.get_text().split()))

原因是使用select方法得到的数据是列表,必须将其中的值提出来才可以使用get_text()方法提取文本,而本次使用select方法后得到数据后并没有将列表中的值提取出来,列表是没有get_text()方法的
在这里插入图片描述
修改的代码如下

date = i.select('.c-abstract')
# date[0]将里面的值提取出来
dict['date'].append(''.join(date[0].get_text().split()))

成功得到文本
在这里插入图片描述

问题参考问题背景使用python的beautifulsoup库爬取网页数据的时候,使用select方法找标签并赋值,get_text()提取文本内容时,报错:AttributeError: ResultSet object has no attribute 'get_text'. You're probably treating a list of elements like a single element. Did you call find_all() when you meant to cal
numpy.array可使用 shape。list不能使用shape。 可以使用np.array(list A)进行转换。 (array转list:array B B.tolist()即可) 补充知识:Pandas使用DataFrame出现错误:AttributeError: ‘list’ object has no attribute ‘astype’ 在使用Pandas的DataFrame时出现了错误:AttributeError: ‘list’ object has no attribute ‘astype’ 代码入下: import pandas as pd pop = {'Neva
python3 server.py 127.0.0.1 8888 Traceback (most recent call last): File “server.py”, line 83, in main() File “server.py”, line 76, in main os.exit() AttributeError: module ‘os’ has no attribute ‘exit’ 部分代码入下: from socket import * import sys,os #实现登录 def do_login(s,user,name,addr): for i in user:
多线程爬虫出现报错AttributeError: ‘NoneType’ object has no attribute ‘xpath’一、前言二、问题三、思考和解决问题四、运行效果 mark一下,本技术小白的第一篇CSDN博客! 最近在捣鼓爬虫,看的是机械工业出版社的《从零开始学Python网络爬虫》。这书吧,一言难尽,优点是案例比较多,说的也还算清楚,但是槽点更多:1、较多低级笔误;2、基础知识一笔带过,简单得不能再简单,对Python基础不好的人不友好;3、代码分析部分,相同的代码反复啰嗦解释多次,而一些该解释的新代码却只字不提;4、这是最重要的一点,但也不全是本书的锅。就是书中
"ResultSet object has no attribute ‘%s’. You’re probably treating a list of elements like a single element. Did you call find_all() when you meant to call find()?" % key AttributeError: ResultSet obje...
soup = get_link_decode(URL) for link in range(10): link = soup.find_all("a",text="{}".format(link)) list_links_docs.append(link) for link in list_links_docs: lis = link.get("href") print(lis) 执行这个程序出现
res = requests.get(url_temp) bs = BeautifulSoup(res.text,'html.parser') movie_list = bs.find_all('ol',class_="grid_view") **for i in movie_list.find_all('li'):** num = ...
import requests from bs4 import BeautifulSoup res = requests.get('https://wordpress-edu-3autumn.localprod.oc.forchange.cn/all-about-the-future_04/') # 把网页解析为BeautifulSoup对象 soup = BeautifulSoup(res.text,'html.parser') items=soup.find_all(class_='comment-
调试递归神经网络(RNN)的时候出现如下错误: AttributeError: module 'tensorflow.contrib.rnn' has no attribute 'core_rnn_cell' 顺便问一句,资源分怎么设置免费啊
python使用pandas模块介绍以及使用,dataframe结构,Series结构,基本数据操作,DataFrame运算,pandas画图,存储,缺失值处理,离散化,合并 weixin_45073642: 提取一行数据,这个数据还是dataframe类型吗 pandas对某一指定列或行进行修改 Metadataer: 成功了,牛B Access入门之基本操作和认识 m0_64425713: 请问下载的网址是什么 TypeError: ‘list‘ object is not callable 2301_76408734: 我找了好久也没找到自己到底哪个列表变量设出问题了,到最后终于发现,我之前定义了一个f(x),然后我下面还有一个地方为了省事,设变量为abcdefg