Scrapy-Splash 问题求教各路大神! Splash 似乎没有渲染网页! - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
Martzki
V2EX    Python

Scrapy-Splash 问题求教各路大神! Splash 似乎没有渲染网页!

  •  1
     
  •   Martzki 2019-02-25 21:35:10 +08:00 3525 次点击
    这是一个创建于 2452 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近毕设需要爬取一些数据,使用了 Scrapy-Splash。
    需要爬取的数据是表格,表内容由 JS 函数填充。
    使用 Splash 渲染网页并将结果返回给 Scrapy,但是使用 Splash 之后似乎并没有任何作用!
    网页: https://www.aqistudy.cn/historydata/daydata.php?city=%E6%AD%A6%E6%B1%89&mOnth=201312
    Splash 版本:3.3.1
    OS 版本:Windows 10 专业版

    表格代码如下:

    <table width="100%" class="table table-condensed table-bordered table-striped table-hover table-responsive" style="margin-bottom:5px"> <tr height=38px> <th align="center" style="background:#d9edf7">日期</th> <th align="center" style="background:#d9edf7">AQI</th> <th align="center" style="background:#d9edf7" width="80px" >质量等级</th> <th align="center" style="background:#d9edf7">PM2.5</th> <th align="center" style="background:#d9edf7">PM10</th> <th align="center" style="background:#d9edf7" class="hidden-xs">SO2</th> <th align="center" style="background:#d9edf7" class="hidden-xs">CO</th> <th align="center" style="background:#d9edf7" class="hidden-xs">NO2</th> <th align="center" style="background:#d9edf7" class="hidden-xs">O3_8h</th> </tr> </table> 

    填充表格的函数如下:

    function showTable(items) { items.forEach(function(item) { $('.table tbody').append('\ <tr>\ <td align="center">' + item.time_point + '</td>\ <td align="center">' + item.aqi + '</td>\ <td align="center"><span style="display:block;width:60px;text-align:center;' + getAQIStyle(item.aqi) + '">' + item.quality + '</span></td>\ <td align="center">' + item.pm2_5 + '</td>\ <td align="center">' + item.pm10 + '</td>\ <td align="center" class="hidden-xs">' + item.so2 + '</td>\ <td align="center" class="hidden-xs">' + item.co + '</td>\ <td align="center" class="hidden-xs">' + item.no2 + '</td>\ <td align="center" class="hidden-xs">' + item.o3 + '</td>\ </tr>' ); }); } 

    不管是在爬虫里使用还是 localhost:8050 调试,得到的表格内容都和上述表格代码里内容一样,表格内容并没有得到。

    7 条回复    2019-02-28 12:18:06 +08:00
    wenbinwu
        1
    wenbinwu  
       2019-02-25 21:48:59 +08:00
    试试调节一下 timeout ?
    Martzki
        2
    Martzki  
    OP
       2019-02-25 21:49:58 +08:00
    @wenbinwu 感谢回复,最高设置到 60 秒,还是不行!
    wenbinwu
        3
    wenbinwu  
       2019-02-25 23:01:07 +08:00
    @Martzki 我试了一下,POST historyapi.php 总是返回 undefined :(
    SpiderXiantang
        4
    SpiderXiantang  
       2019-02-26 00:51:43 +08:00
    scrapy+selenium 试试?
    SpiderXiantang
        5
    SpiderXiantang  
       2019-02-26 01:18:12 +08:00
    找到了 翻译一下这段代码就可以解决了 method = "GETDAYDATA", object = {city: "武汉", month: "201312"} , callback = (obj), period = 6

    只是对接口的数据进行了加密
    ```
    function getServerData(method, object, callback, period) {
    const key = hex_md5(method + JSON.stringify(object));
    const data = getDataFromLocalStorage(key, period);
    if (!data) {
    var param = getParam(method, object);
    $.ajax({
    url: 'api/historyapi.php',
    data: {
    hd: param
    },
    type: "post",
    success: function(data) {
    data = decodeData(data);
    obj = JSON.parse(data);
    if (obj.success) {
    if (period > 0) {
    obj.result.time = new Date().getTime();
    localStorageUtil.save(key, obj.result)
    }
    callback(obj.result)
    } else {
    console.log(obj.errcode, obj.errmsg)
    }
    }
    })
    } else {
    callback(data)
    }
    }
    ```
    Martzki
        6
    Martzki  
    OP
       2019-02-26 10:29:04 +08:00
    @SpiderXiantang 多谢,用 splash 是因为了解到比 selenium 效率高。另外我对 web 实在是没有什么基础,能不能请您提示一下下一步应该怎么处理
    Martzki
        7
    Martzki  
    OP
       2019-02-28 12:18:06 +08:00
    后面换用 selenium+PhantomJS 可以了,splash 还是没能成功
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     4714 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 25ms UTC 09:45 PVG 17:45 LAX 01:45 JFK 04:45
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86