源代码地址: https://github.com/txf7337/dabao-spider
基本配置
jdbc数据库 //mysql测试过
文件下载,文字识别的线程数以及线程爬取的间隔
任务周期
文件保存目录
代理的配置
<host>主机名
<port>端口号
<auth>用户名密码(如果需要的话)
数据源配置
线程数、线程爬取的间隔、是否使用代理
数据源种子
<seed url="http://www.okbuy.com/product/filter?category=54&per_page=*00" from="1" to="1" query="li.pc_list_hover>div.img>a" attr="href"> <columns> <column name="style" value="运动鞋" type="VARCHAR(100)" /> </columns> </seed>
1. 种子url,*代表页数,from-to是从第几页爬到第几页
2. Query爬取数据url的规则(jquery规则)
3. Attr拿该标签的attr属性内容,如果为空,则拿该标签的文本内容
4. Columns这个种子能确定的某些字段
数据源爬取规则
<columns> <column name="id" type="INT(11)"> <rule type="html" value="ul.pProductTitle>li>p" index="0" /> </column> <column name="brand" type="INT(11)"> <rule type="text" url=" http://www.okbuy.com/product/ajax_product_info/{id}" value="0" /> </column> <column name="arno" type="VARCHAR(100)"> <rule type="json" url="http://www.okbuy.com/product/ajax_product_info/{id}" value="/o/salepr" index="0" /> </column> <column name="price" type="DOUBLE" ocr_column="price_ocr_url"> <rule type="html" value="ul#summary>li#summary-price>div.dd>strong>img" index="0" attr="src"/> </column> <column name="img_1" type="VARCHAR(1000)" file_column="img_1_url" file_path="{yyyy}/{MM}/" > <rule type="html" value="table.multi_view>tbody>tr>td>a" index="0" attr="href"/> </column> </columns>
1. Column:字段
如果seed.column里有的字段,最好不要再出现。(seed里有的字段,说明这个字段值已经在确定了,不需要再抽取)
2. Name:字段名
唯一的,一张表可能有两个字段名字相同吗?
3. Type:字段类型
4. Ocr_column:需要识别的图片url字段
需要识别的图片的url字段
5. File_column:需要下载的文件url字段
需要下载的文件的url字段
6. File_path:下载的相对路径
完整路径:basepath+数据源+file_path
7. Overwrite:要是该字段已经有值了,是否覆盖。默认是false
8. Rule.type:爬取的类型
A. Html query规则抽取
B. Json json规则抽取
C. Xml xml规则抽取
D. Text 正则规则抽取
9. Rule:value:爬取的规则
A. Html对应query规则
B. Json、xml对应xpath规则
C. Text对应正则
10. Rule:url:异步请求的url
如果是json、xml规则,rule.url不能为空。{name}对应url里的参数,name必须有值,name就是字段名
11. Rule:attr: 拿该标签的attr属性内容,如果为空,则拿该标签的文本内容
12. Rule:index:拿第几个标签,默认是0(第一个)
附件里start.bat可以直接运行
最后如果有人想要源码的可以给我发邮件
我希望能继续开发下去,把这个小程序写强大