快捷搜索:  汽车  科技

spider操作(前嗅ForeSpider脚本教程基础对象)

spider操作(前嗅ForeSpider脚本教程基础对象)如果在导航栏的采集预览中找到多个栏目,我们需要的个别栏目在爬虫的链接过滤中很难得到的时候。那就可以在网页源码中找到需要的链接和栏目标题,用如下脚本3.脚本应用​2.成员方法​

今天,小编给大家介绍一下:前嗅ForeSpider脚本中的基础对象,主要内容有:数组类array、键值对类hash、文件类file、字段操作类field。具体内容如下:

一.数组类array

array 类为数组类。

1.类成员

spider操作(前嗅ForeSpider脚本教程基础对象)(1)

spider操作(前嗅ForeSpider脚本教程基础对象)(2)

2.成员方法

spider操作(前嗅ForeSpider脚本教程基础对象)(3)

spider操作(前嗅ForeSpider脚本教程基础对象)(4)

3.脚本应用

如果在导航栏的采集预览中找到多个栏目,我们需要的个别栏目在爬虫的链接过滤中很难得到的时候。那就可以在网页源码中找到需要的链接和栏目标题,用如下脚本

示例:

array city;//定义一个数组

city = [{name:"北京" url:"/zhaopin/diqu/beijing/"}

{name:"天津" url:"/zhaopin/diqu/tianjin/"}

{name:"河北" url:"/zhaopin/diqu/huabei/"}];

for(int i = 0;i < city.length; i ){

url u;

u.title = city[i].name; //需要输出的栏目标题

u.urlname = "http://www.gaoxiaojob.com" city[i].url;

//拼接出需要的栏目链接

u.tmplid = 2; //指定处理模板

u.entryid = CHANN.id;

RESULT.AddLink(u); //输出

}

脚本的输出结果

spider操作(前嗅ForeSpider脚本教程基础对象)(5)

spider操作(前嗅ForeSpider脚本教程基础对象)(6)

spider操作(前嗅ForeSpider脚本教程基础对象)(7)

spider操作(前嗅ForeSpider脚本教程基础对象)(8)

【输出结果】

二.键值对类hash

hash 类为键值对类。

1.类成员

spider操作(前嗅ForeSpider脚本教程基础对象)(9)

spider操作(前嗅ForeSpider脚本教程基础对象)(10)

spider操作(前嗅ForeSpider脚本教程基础对象)(11)

spider操作(前嗅ForeSpider脚本教程基础对象)(12)

2.成员方法

spider操作(前嗅ForeSpider脚本教程基础对象)(13)

spider操作(前嗅ForeSpider脚本教程基础对象)(14)

spider操作(前嗅ForeSpider脚本教程基础对象)(15)

spider操作(前嗅ForeSpider脚本教程基础对象)(16)

Iter遍历hash样例:hash hs;

hs.aa = 1;

hs.bb = 2;

hs.Iter(function(n v){

echo(n ":" v "<br>");

});

三.文件类file

file 类为文件操作类。

一.类成员:

spider操作(前嗅ForeSpider脚本教程基础对象)(17)

spider操作(前嗅ForeSpider脚本教程基础对象)(18)

二.成员方法:

spider操作(前嗅ForeSpider脚本教程基础对象)(19)

spider操作(前嗅ForeSpider脚本教程基础对象)(20)

spider操作(前嗅ForeSpider脚本教程基础对象)(21)

猜您喜欢: