python怎样读取网页中的文本_python - 使用BeautifulSoup从已抓取页面中提取文本_web-scraping_酷徒编程知识库...

編程和網頁抓取的新手,並且在使BeautifulSoup僅從給定頁面中提取文本時遇到一些麻煩。

下面是我正在使用的內容:import requests

from bs4 import BeautifulSoup

url = 'https://www.tsn.ca/panarin-tops-2019-free-agent-frenzy-class-1.1303592'

headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36'}

page = requests.get(url)

soup = BeautifulSoup(page.text, 'html.parser')

players = soup.find_all('td').text

print(players)

返回以下內容:Traceback (most recent call last):

File "tsn.py", line 10, in

players = soup.find_all('td').text

File "/home/debian1/.local/lib/python3.5/site-packages/bs4/element.py", line 1620, in __getattr__

"ResultSet object has no attribute '%s'. You're probably treating a list of items like a single item. Did you call find_all() when you meant to call find()?" % key

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

我也看到過BS文檔中使用的.get_text(),但是,返回相同的錯誤。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值