【问题标题】:Beautifulsoup webscraping.Beautifulsoup 网页抓取。
【发布时间】:2018-09-22 19:15:20
【问题描述】:

我正在尝试从 DnDbeyond 抓取数据。我正在使用 Beautifulsoup 和 python,并且已经能够通过使用“Div”标签和“Find_all”类获得一些我需要的信息,但我似乎无法从这些包含字符统计信息的格式化块中找到信息.

<div class="ct-skills__col--skill">Animal Handling</div>

我应该可以搜索soup.find("div", {"class": "ct-skills__col--skill"})

对吗?

这就是我当前的代码的样子。

from bs4 import BeautifulSoup
import requests

resp = requests.get('https://www.dndbeyond.com/characters/4741434')
soup = BeautifulSoup(resp.text, 'lxml')

divTag = soup.find_all("div", {"class": "container"})

这让我感动

[<div class="container">
<div class="main content-container" id="content">
<section class="primary-content" role="main">
<div data-character-endpoint="/character/4741434/json" data-character-id="4741434" data-read-only="true" id="character-sheet-target"></div>
<script src="/Content/1-0-482-0/React/CharacterTools/dist/characterSheet.bundle.min.js" type="text/javascript"></script>
</section>
</div>
</div>]

我知道我的信息在“字符表目标”下,但我不知道如何在其中获取信息/类。

很抱歉,如果这是我不知道如何解释这一点的 rambely。

【问题讨论】:

  • 此页面在客户端使用Javascript生成页面。
  • 好吧,有没有办法获取这些信息?
  • 想通了。不得不使用 Selenium 来抓取我猜想的 javascript 内容。

标签: python beautifulsoup


【解决方案1】:

你可以使用他们的json api,不需要selenium,见下面的代码。

import requests
req = requests.get('https://www.dndbeyond.com/character/4741434/json')
print req.json()

【讨论】:

  • 我不知道它存在。这使这种方式更容易,非常感谢。当我在网上搜索时,我只是看到一群人说也许有一天要提供一个 API,但那个 API 还不存在。
  • 很高兴为您提供帮助!
【解决方案2】:

我几乎完成了整个结构的充实。

Objective-C 源代码包含所有类定义。

https://github.com/mouser/BeyondDnD

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-25
    • 2014-06-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多