当我尝试使用BeautifulSoup从网站抓取时缺少文本

超级Chidog

我正在尝试从伦敦证券交易所的新闻文章中抓取正文,但是当我尝试使用BeautifulSoup将其拉出时,它并未出现。有谁知道我该如何获取此信息?

单击检查时可以找到标签,但是在查看源代码(Ctrl + U)时,不会显示文本。我认为该信息可能是从另一个站点加载到该站点的,但是我对此不确定,也不知道如何抓取它。

我正在查看的网站是:https : //www.londonstockexchange.com/news-article/PFG/interim-results-for-six-months-ended-30-june-2020/14665452

我正在尝试获取有关中期业绩的主要内容。

安德烈·凯斯利(Andrej Kesely)

文章存储在页面内<script>标签内。您可以使用以下示例将其提取:

import json
import requests
from bs4 import BeautifulSoup


url = 'https://www.londonstockexchange.com/news-article/PFG/interim-results-for-six-months-ended-30-june-2020/14665452'

soup = BeautifulSoup(requests.get(url).content, 'html.parser')
data = soup.select_one('#ng-lseg-state').string.replace('&q;', '"').replace('&l;', '<').replace('&g;', '>').replace('&a;', '&').replace('&s;', "'")
data = json.loads(data)

# uncomment this to print all data:
# print(json.dumps(data, indent=4))

def find_news_article(data):
    if isinstance(data, dict):
        for k, v in data.items():
            if k == 'newsArticle':
                yield v
            else:
                yield from find_news_article(v)
    elif isinstance(data, list):
        for v in data:
            yield from find_news_article(v)

article = BeautifulSoup(next(find_news_article(data))['value'], 'html.parser')

# print text from article on screen:
print(article.get_text(strip=True, separator='\n'))

印刷品:

RNS Number : 1348X
Provident Financial PLC
26 August 2020
Provident Financial plc
Interim results for the six months ended 30 June 2020
Provident Financial plc ('the Group') is the leading provider of credit products to consumers who are underserved by mainstream lenders. The Group serves c.2.2 million customers and its operations consist of Vanquis Bank, Moneybarn, and the Consumer Credit Division ('CCD') comprising Provident home credit and Satsuma.

...and so on.

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用BeautifulSoup抓取网站后缺少文本

使用BeautifulSoup抓取网站时显示符号

使用BeautifulSoup抓取网站时阅读页码

当我抓取网站时,我产生的项目去哪里了?

当我们使用文本文件收集器导出指标时,WMI 导出器在尝试抓取指标时出错

我无法使用BeautifulSoup抓取HTML文本

每当我尝试使用网站进行测试时,都会在“电子邮件”文本框中收到错误消息

当我尝试在Cassandra中使用group by进行查询时“缺少EOF AT GROUP ...”

使用 BeautifulSoup 或 Selenium 抓取网站时找不到数据

我正在尝试通过网络抓取网站,当我试图将其转换为CSV文件时,数据无法进入正确的列

使用BeautifulSoup抓取特定网站

使用 python 抓取网站 - BeautifulSoup

当我尝试使用 useState 查看我的文本时,为什么会出现错误?

当我尝试通过BeautifulSoup获取<table>时,它为空

Beautifulsoup 抓取 - 缺少可扩展的标题文本

错误:当我在 React 中尝试使用 Jest 进行测试时,无法找到包含文本的元素

抓取网站时缺少HTML元素。蟒蛇

在Python上使用BeautifulSoup4时,为什么当我尝试打印“ <p>”元素时,结果为'None'?

使用beautifulSoup在<a href>中抓取文本时,结果变为空

当我使用变量时,抓取不会转移

网站元素显示在浏览器中,但当我尝试使用检查元素访问它时隐藏

当我从网站上抓取数据时,它仅返回换行符

尝试抓取网站时连接拒绝错误

抓取网站 html 以获取文本数据时出现 lxml 错误。尝试了几次迭代

如何使用BeautifulSoup抓取缺少标签的网页

当我尝试抓取一些 URL 时,它返回“无表”

“TypeError:'NoneType' 类型的参数不可迭代”当我尝试进行网络抓取时

为什么我在beautifulsoup 中的find 方法在抓取coursera 网站时返回None?

部署失败 - 缺少依赖项当我使用注释时