【问题标题】:I can't scrap a part of an html code (BeautifulSoup)我无法废弃部分 html 代码 (BeautifulSoup)
【发布时间】:2022-08-03 23:14:25
【问题描述】:

我正在尝试在页面底部获取此页面https://www.binance.com/es-LA/altcoins/new的新币信息表。但我对此有很多问题。

当我尝试查找 html 代码的某些部分(包含表格信息的部分)时,我得到无类型对象。我试着看div经过div但我总是在同一部分遇到同样的问题。

Buscador = requests.get(\'https://www.binance.com/es-LA/altcoins/new\', \'lxml\')

BuscadorSopeado = bs(Buscador.text, features = \'html.parser\')

BusquedaPrimero = BuscadorSopeado.find(name = \'div\', attrs = {\'class\': \"css-1t63o3e\"})

其中类型(BusquedaPrimero)= 无。

如果我看到 html 代码的前一部分,我会得到一条大线:

IN:
BusquedaPrimero = BuscadorSopeado.find(name = \'div\', attrs = {\'class\': \"css-pcu8qt\"})

OUT:    
<div class=\"css-pcu8qt\"><style data-emotion-css=\"18rcfta\">.css-18rcfta{box-sizing:border-box;margin:0;min-width:0;overflow-wrap:break-word;font-size:24px;font-weight:600;line-height:32px;color:#1E2329;margin-bottom:64px;}@media screen and (min-width:767px){.css-18rcfta{font-size:32px;font-weight:600;line-height:40px;}}@media screen and (min-width:1023px){.css-18rcfta{font-size:40px;font-weight:600;line-height:48px;}}</style><h2 class=\"container__title css-18rcfta\" data-bn-type=\"text\">Principales criptoactivos por porcentaje de la capitalización total de mercado</h2><div class=\"sc-gtsrHT cVacoL cmc-btc-percentage-chart\" id=\"dominance-percentage\"><style data-emotion-css=\"1ig4gr6\">.css-1ig4gr6{box-sizing:border-box;margin:0;min-width:0;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;width:30px;height:30px;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:justify;-webkit-justify-content:space-between;-ms-flex-pack:justify;justify-content:space-between;margin-left:auto;margin-right:auto;margin-top:337px;margin-bottom:337px;}</style><div class=\"css-1ig4gr6\"><style data-emotion-css=\"2bc2yz animation-hqgv56\">
        
*AND MORE THINGS THAT I CUT.*

我是新的报废东西,所以如果解决方案很简单,我很抱歉。

    标签: python html beautifulsoup spyder screen-scraping


    【解决方案1】:

    我不知道您在网页中要查找的确切内容,但有两种解释: 首先,网站阻止您的请求,因此您应该看到 404 状态或 403,如果是这种情况,我建议在您的请求中添加带有“user_agent”的“标题” 其次,如果您尝试抓取使用 javascript 的网站,您可能会错过一些信息,因为遗憾的是 bs4 库无法获取 javascript 组件

    【讨论】:

      猜你喜欢
      • 2022-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-10
      • 2012-11-14
      相关资源
      最近更新 更多