spider

您所在的位置:网站首页 pageloadtimeout spider

spider

#spider| 来源: 网络整理| 查看: 265

spider-flow 使用有一年多的时间。在使用中发现网上教程不多。selenium 节点变量不好使用,经常不明所以的就采不到数据。

今天分析下:www.zoomlion.com/other/searc… 反爬,并用spider-flow 实现翻页采集。

列表页

查看列表页源码,发现新闻列表内容并不在源码,打开chrome 开发者工具,查看网络请求,

屏幕快照 2022-07-03 上午8.47.49.png

分析

发现第一个请求最有可能是,但这%3Cli 这是啥东西,不认识,猜可能是unicode 编码,或是base64编码之类的。在网上打开unicode 解码工具,一看正是。

屏幕快照 2022-07-03 上午8.50.54.png 就是这个请求,我们深挖下这个请求,应该有关键词,翻页之类的变量。

屏幕快照 2022-07-03 上午8.52.10.png

一看很蒙,这应该加密处理了。不过我们不怕,spider-flow 有selenium节点,支持渲染请求。

处理

屏幕快照 2022-07-03 上午8.54.36.png

输入url, 并给变量命名resp2,(在这重命名,是为了避免被后面覆盖).

屏幕快照 2022-07-03 上午8.59.17.png 变量抽取,首先 resp2 是个SeleniumResponse对象,需要转成SpiderResponse对象respele,(我发现SeleniumResponse 抽取时不太好用) urls 是抽取的列表页url 数组。 inext 是翻页变量,这的翻页需要点击下面的下一页按钮。

屏幕快照 2022-07-03 上午8.59.26.png

屏幕快照 2022-07-03 上午8.54.45.png

函数节点,跟selenium 节点配合使用,在函数节点编写命令操作selenium 页面。

屏幕快照 2022-07-03 上午9.05.35.png

第一个函数表示选择a.next 这个节点,并点击。 第二个函数表示休息10s, 让页面完成渲染。 在执行条件处写上, ${inext < 10} 表示循环10 次。

详情页

详情页就比较简单了,在源码中可以找到标题,正文,时间等字段。 用网络请求节点,变量节点

屏幕快照 2022-07-03 上午9.10.49.png

屏幕快照 2022-07-03 上午9.10.59.png

源码 最后,附上完成的xml配置。 {;spiderName;:;中联重科;,;submit-strategy;:;child;,;threadCount;:;1;} {;shape;:;start;} {;value;:;提取项目名、详情地址;,;loopVariableName;:;;,;variable-name;:[;respele;,;urls;,;inext;],;variable-description;:[;;,;;,;;],;loopCount;:;;,;variable-value;:[;${resp2.html.element()};,;${respele.selectors('ul.search_list li a')};,;${inext==null?0:inext+1};],;shape;:;variable;} {;value;:;抓取详情页;,;loopVariableName;:;index;,;method;:;GET;,;sleep;:;300;,;timeout;:;120000;,;response-charset;:;;,;retryCount;:;3;,;retryInterval;:;;,;body-type;:;none;,;body-content-type;:;text/plain;,;loopCount;:;${urls.size()};,;url;:;https://www.zoomlion.com${urls[index].attr('href')};,;proxy;:;;,;request-body;:;;,;follow-redirect;:;1;,;tls-validate;:;1;,;cookie-auto-set;:;1;,;repeat-enable;:;0;,;shape;:;request;} {;value;:;;,;condition;:;;} {;value;:;提取详情页;,;loopVariableName;:;;,;variable-name;:[;title;,;date1;,;content;],;variable-description;:[;;,;;,;;],;loopCount;:;;,;variable-value;:[;${resp.selector('h1,h4').text()};,;${resp.regx('(\\d{1,2}\\/\\d{1,2}\\.\\d{4})')};,;${resp.selector('#main_content,div.details')};],;shape;:;variable;} {;value;:;;,;exception-flow;:;0;,;lineWidth;:;2;,;line-style;:;sharp;,;lineColor;:;black;,;condition;:;;,;transmit-variable;:;1;} {;value;:;输出;,;loopVariableName;:;;,;datasourceId;:;da9568e3380ea467cc18817a76443f61;,;tableName;:;f_news;,;csvName;:;C:\\DataChange\\32.csv;,;csvEncoding;:;UTF-8;,;output-name;:[;title;,;edittime;,;content1;,;url;,;source;,;channel;,;nohtml;],;loopCount;:;;,;output-value;:[;${title};,;${date1};,;${content.pichtml()};,;${resp.url};,;中联重科;,;news;,;${content.text()};],;output-all;:;0;,;output-database;:;0;,;output-csv;:;0;,;shape;:;output;} {;value;:;;,;condition;:;;} {;value;:;Selenium;,;nodeVariableName;:;resp2;,;loopVariableName;:;;,;loopCount;:;;,;pageLoadTimeout;:;;,;implicitlyWaitTimeout;:;;,;driverType;:;chrome;,;window-size;:;;,;user-agent;:;;,;arguments;:;;,;url;:;https://www.zoomlion.com/other/search.html?key=%u8A79%u7EAF%u65B0;,;proxy;:;;,;cookie-auto-set;:;1;,;repeat-enable;:;0;,;headless;:;0;,;javascript-disabled;:;0;,;image-disabled;:;0;,;plugin-disable;:;1;,;java-disable;:;1;,;incognito;:;0;,;sandbox;:;0;,;hide-scrollbar;:;0;,;maximized;:;0;,;shape;:;selenium;} {;value;:;;,;exception-flow;:;0;,;lineWidth;:;2;,;line-style;:;sharp;,;lineColor;:;black;,;condition;:;;,;transmit-variable;:;1;} {;value;:;;,;exception-flow;:;0;,;lineWidth;:;2;,;line-style;:;sharp;,;lineColor;:;black;,;condition;:;;,;transmit-variable;:;1;} {;value;:;执行函数;,;loopVariableName;:;;,;loopCount;:;;,;function;:[;${resp2.selector('a.next').click()};,;${resp2.sleep(10000)};],;shape;:;function;} {;value;:;;,;exception-flow;:;0;,;lineWidth;:;2;,;line-style;:;sharp;,;lineColor;:;black;,;condition;:;;,;transmit-variable;:;1;} {;value;:;;,;exception-flow;:;0;,;lineWidth;:;2;,;line-style;:;sharp;,;lineColor;:;blue;,;condition;:;${inext;10};,;transmit-variable;:;1;} 复制代码


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3