【问题标题】:Scraping Dynamic Javascript with Qt5使用 Qt5 抓取动态 Javascript
【发布时间】:2018-09-02 18:47:24
【问题描述】:

我遇到了一个小问题。我有一个使用 javascript 的视频游戏在线拍卖网站。确切地说,我想抓取的数据是在 x-template 类型的脚本块中。我无法获取实际数据,只能获取源中的脚本。

这是我的代码:

def render(source_url):

    import sys
    from PyQt5.QtWidgets import QApplication
    from PyQt5.QtCore import QUrl
    from PyQt5.QtWebEngineWidgets import QWebEngineView

    class Render(QWebEngineView):
        def __init__(self, url):
            self.html = None
            self.app = QApplication(sys.argv)
            QWebEngineView.__init__(self)
            self.loadFinished.connect(self._loadFinished)
            #self.setHtml(html)
            self.load(QUrl(url))
            self.app.exec_()

        def _loadFinished(self, result):
            # This is an async call, you need to wait for this
            # to be called before closing the app
            self.page().toHtml(self._callable)

        def _callable(self, data):
            self.html = data
            # Data has been stored, it's safe to quit the app
            self.app.quit()

    return Render(source_url).html

url = "https://www.pathofexile.com/trade/search/Bestiary/blkdmmofg"

f = open("html_out.txt", "w", encoding = "utf8")
f.write(str(render(url)))
f.close()

当我手动检查第一个项目的货币文本并尝试在我的文件中找到它时,它找不到它,因为它是动态的。

在 html_out.txt 文件中,脚本的开头如下所示:

<script type="x-template" id="trade-exchange-item-template">

然后是我正在以这种形式搜索的数据:

<span v-else class="currency-text">{{currencyText(priceInfo.currency)}}</span>

如何才能完全加载网站和脚本,然后使用正确的数据获取 HTML?

提前致谢!

【问题讨论】:

  • 我检查了x-template,好像是用Vue JS写的。但是仍然找不到任何解决方案。

标签: javascript python dynamic web-scraping xtemplate


【解决方案1】:

如果没有实际的客户,我似乎无法抓取它。不过,它与 Selenium 配合得很好。

【讨论】:

    猜你喜欢
    • 2022-01-08
    • 1970-01-01
    • 1970-01-01
    • 2018-10-01
    • 2021-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多