如何使用scrapy抓取angularjs网站?

2024-06-24 13:40:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要一种方法来获得所有博彩活动的赔率

我正在使用Scrapy+Splash获取该站点的第一个javascript加载内容。但要想获得所有其他的赔率,我必须点击“意大利联赛”等等

我怎么能做到呢?在


Tags: 方法内容站点javascriptscrapysplash博彩赔率
1条回答
网友
1楼 · 发布于 2024-06-24 13:40:15

您可以模拟行为,例如滚动单击,方法是编写JavaScript脚本,并告诉Splash在呈现页面时执行该脚本。在

一个小例子:

您可以定义一个JavaScript函数,该函数选择页面中的元素,然后单击该元素:

(来源:splash doc

    Get button element dimensions with javascript and perform mouse click.
_script = """
function main(splash)
    assert(splash:go(splash.args.url))
    local get_dimensions = splash:jsfunc([[
        function () {
            var rect = document.getElementById('button').getClientRects()[0];
            return {"x": rect.left, "y": rect.top}
        }
    ]])
    splash:set_viewport_full()
    splash:wait(0.1)
    local dimensions = get_dimensions()
    splash:mouse_click(dimensions.x, dimensions.y)

      Wait split second to allow event to propagate.
    splash:wait(0.1)
    return splash:html()
end
"""

然后,当request时,修改endpoint,并将其设置为"execute",然后将"lua_script": _script添加到参数中。在

^{pr2}$

您将找到有关splash脚本的所有信息here

相关问题 更多 >