火车采集器/附件上传
来自站长百科
上传文件到网站是一个比较复杂的过程,需要有一定编程基础才好理解。这里只提供编写方法。
火车采集器自2009版起支持附件上传到网站,这个功能可以将采集来的图片或文件以附件的形式发布到论坛或cms里边去.此功能标准版或更高版本支持.
使用这个功能很方便,主要是模块做好就可以使用了.这里讲一下如何制作附件发布模块.以dz7.0为例(注意,需具备编写模块的能力):
先发一个附件帖,看下抓取的数据包.具体的来源页,post页等和一般的模块制作并无两样,只讲post内容的制作.
-----------------------------7d93e2f30532 Content-Disposition: form-data; name="formhash" 872e9a0a -----------------------------7d93e2f30532 Content-Disposition: form-data; name="handlekey" newthread -----------------------------7d93e2f30532 Content-Disposition: form-data; name="wysiwyg" 0 -----------------------------7d93e2f30532 Content-Disposition: form-data; name="iconid" -----------------------------7d93e2f30532 Content-Disposition: form-data; name="updateswfattach" 0 -----------------------------7d93e2f30532 Content-Disposition: form-data; name="subject" caijititle111 -----------------------------7d93e2f30532 Content-Disposition: form-data; name="checkbox" 0 -----------------------------7d93e2f30532 Content-Disposition: form-data; name="message" caijicontent111 -----------------------------7d93e2f30532 Content-Disposition: form-data; name="localid[]" -----------------------------7d93e2f30532 Content-Disposition: form-data; name="attachperm[]" 0 -----------------------------7d93e2f30532 Content-Disposition: form-data; name="attachprice[]" 0 -----------------------------7d93e2f30532 Content-Disposition: form-data; name="attachdesc[]" -----------------------------7d93e2f30532 Content-Disposition: form-data; name="attachdesc[]" fileaa -----------------------------7d93e2f30532 Content-Disposition: form-data; name="localid[]" 1 -----------------------------7d93e2f30532 Content-Disposition: form-data; name="attachperm[]" 100 -----------------------------7d93e2f30532 Content-Disposition: form-data; name="attachprice[]" 200 -----------------------------7d93e2f30532 Content-Disposition: form-data; name="attachdesc[]" filebb -----------------------------7d93e2f30532 Content-Disposition: form-data; name="localid[]" 2 -----------------------------7d93e2f30532 Content-Disposition: form-data; name="attachperm[]" 300 -----------------------------7d93e2f30532 Content-Disposition: form-data; name="attachprice[]" 400 -----------------------------7d93e2f30532 Content-Disposition: form-data; name="localid[]" 3 -----------------------------7d93e2f30532 Content-Disposition: form-data; name="attachperm[]" 0 -----------------------------7d93e2f30532 Content-Disposition: form-data; name="attachprice[]" 0 -----------------------------7d93e2f30532 Content-Disposition: form-data; name="tags" -----------------------------7d93e2f30532 Content-Disposition: form-data; name="addtags" '''+可用标签''' -----------------------------7d93e2f30532 Content-Disposition: form-data; name="readperm" -----------------------------7d93e2f30532 Content-Disposition: form-data; name="price" -----------------------------7d93e2f30532 Content-Disposition: form-data; name="attach[]"; filename="" Content-Type: application/octet-stream -----------------------------7d93e2f30532 Content-Disposition: form-data; name="attach[]"; filename="E:\Documents and Settings\Administrator\桌面\a.txt" Content-Type: text/plain '''这是内容a''' -----------------------------7d93e2f30532 Content-Disposition: form-data; name="attach[]"; filename="E:\Documents and Settings\Administrator\桌面\b.txt" Content-Type: text/plain '''这是内容b'''' -----------------------------7d93e2f30532 Content-Disposition: form-data; name="attach[]"; filename="" Content-Type: application/octet-stream -----------------------------7d93e2f30532--
来讲一下制作步骤,首先,将 -----------------------------7d91a5211046a 替换为 -----------------------------7dlocoyspider,然后,寻找文件上传部分的代码,确认其样式.可以分析出如下格式:
-----------------------------7dlocoyspider Content-Disposition: form-data; name="attachdesc[]" fileaa -----------------------------7dlocoyspider Content-Disposition: form-data; name="localid[]" 1 -----------------------------7dlocoyspider Content-Disposition: form-data; name="attachperm[]" 100 -----------------------------7dlocoyspider Content-Disposition: form-data; name="attachprice[]" 200 -----------------------------7dlocoyspider Content-Disposition: form-data; name="attach[]"; filename="E:\Documents and Settings\Administrator\桌面\a.txt" Content-Type: text/plain
这是内容a
注意,这个信息里是可以设置附件等的权限的,但程序目前只提供了循环id,文件地址.所以这里只能写固定值,比如一般的就是默认的0,整理成程序可识别的样式.
{本地文件循环:内容}-----------------------------7dlocoyspider Content-Disposition: form-data; name="attachdesc[]" -----------------------------7dlocoyspider Content-Disposition: form-data; name="localid[]" [循环文件ID] -----------------------------7dlocoyspider Content-Disposition: form-data; name="attachperm[]" 0 -----------------------------7dlocoyspider Content-Disposition: form-data; name="attachprice[]" 0 -----------------------------7dlocoyspider Content-Disposition: form-data; name="attach[]"; filename="[本地文件路径]" Content-Type: image/gif {/本地文件循环}
这样上传部分就做好了,其它的抓取的数据包替换一下即可.对于那些可要可不要的参数,可以不使用,去掉,最后,可以组合出这样的post参数
{本地文件循环:内容}-----------------------------7dlocoyspider Content-Disposition: form-data; name="attachdesc[]" -----------------------------7dlocoyspider Content-Disposition: form-data; name="localid[]" [循环文件ID] -----------------------------7dlocoyspider Content-Disposition: form-data; name="attachperm[]" 0 -----------------------------7dlocoyspider Content-Disposition: form-data; name="attachprice[]" 0 -----------------------------7dlocoyspider Content-Disposition: form-data; name="attach[]"; filename="[本地文件路径]" Content-Type: image/gif {/本地文件循环}-----------------------------7dlocoyspider Content-Disposition: form-data; name="formhash" [登录随机值2] -----------------------------7dlocoyspider Content-Disposition: form-data; name="subject" [标签:标题] -----------------------------7dlocoyspider Content-Disposition: form-data; name="message" [标签:内容] -----------------------------7dlocoyspider--
测试一下,成功上传即可。