爬虫,工具 - Splash

Posted allen2333

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了爬虫,工具 - Splash相关的知识,希望对你有一定的参考价值。

What is it?

Splash is a javascript rendering service. It’s a lightweight web browser with an HTTP API
http://splash.readthedocs.io/en/stable/

用途

爬虫方面可以抓取JS渲染的页面(selenium也可以解决此问题)

用法

  1. 用docker开启Splash服务(可以分布式,在多台机器上用docker开启Splash服务)
  2. Python中用拼接Lua脚本,请求Splash的API
import requests
from urllib.parse import quote

lua = ‘‘‘
function main(splash)
    return ‘hello‘
end
‘‘‘

url = ‘http://localhost:8050/execute?lua_source=‘ + quote(lua)
response = requests.get(url)
print(response.text)

以上是关于爬虫,工具 - Splash的主要内容,如果未能解决你的问题,请参考以下文章

Python爬虫编程思想(104):Splash基础(支持Lua的轻量级浏览器)

Python爬虫编程思想(104):Splash基础(支持Lua的轻量级浏览器)

python爬虫之Splash使用初体验

Python爬虫编程思想(107):基于Splash的爬虫--对象属性

爬虫进阶-JS自动渲染Scrapy_splash组件的使用

Python爬虫编程思想(105):基于Splash的爬虫--第1个Lua脚本