微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Binance公告页面上的Beautiful Soup Web Scraper落后5分钟

如何解决Binance公告页面上的Beautiful Soup Web Scraper落后5分钟

我使用 bs4 构建了一个网络爬虫,目的是在发布新公告时获得通知,目前我正在使用“列表”一词而不是所有公告关键字进行测试。出于某种原因,当我比较它确定发布新公告的时间与它在网站上发布的实际时间时。时间相差 5 分钟。

This is actual time it was announced

from bs4 import BeautifulSoup
from requests import get
import time
import sys

x = True
while x == True:
    time.sleep(30)
    # Data for the scraping
    url = "https://www.binance.com/en/support/announcement"
    response = get(url)
    html_page = response.content
    soup = BeautifulSoup(html_page,'html.parser')
    news_list = soup.find_all(class_ = 'css-qinc3w')

    # Create a bag of key words for getting matches
    key_words = ['list','token sale','open Trading','opens Trading','perpetual','defi','uniswap','airdrop','adds','updates','enabled','Trade','support']

    # Empty list
    updated_list = []

    for news in news_list:
        article_text = news.text

        if ("list" in article_text.lower()):
            updated_list.append([article_text])

        if len(updated_list) > 4:
            print(time.asctime( time.localtime(time.time()) ))
            print(article_text)
            sys.exit()

列表长度增加 1 到 5 时的响应导致打印以下时间和新公告: 2021 年 5 月 28 日星期五 04:17:39, 币安将上线 Livepeer (LPT)

我不确定为什么会这样,起初我以为我被节流了,但再看看robot.txt,我没有看到我应该被节流的任何理由,而且我包括了30秒的睡眠时间应该足以进行网页抓取而不会出现任何问题。任何帮助或替代解决方案,将不胜感激。

我的问题是:

为什么晚了 5 分钟?为什么它在网站发布后不通知我,与在网站上发布的时间相比,程序需要多 5 分钟才能识别出有新帖子。

解决方法

from xrzz import http ## give it try using my simple scratch module
import json

url = "https://www.binance.com/bapi/composite/v1/public/cms/article/list/query?type=1&pageNo=1&pageSize=30"

req = http("GET",url=url,tls=True).body().decode()

key_words = ['list','token sale','open trading','opens trading','perpetual','defi','uniswap','airdrop','adds','updates','enabled','trade','support']

for i in json.loads(req)['data']['catalogs']:
    for o in i['articles']:
        if key_words[0] in o['title']:
            print(o['title'])

输出:

Result

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?