火车浏览器官方论坛

 找回密码
 立即注册
查看: 33546|回复: 3

火车浏览器开发版SDK发布(C#和Java)

[复制链接]

46

主题

101

帖子

688

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
688
发表于 2014-8-19 11:56:38 | 显示全部楼层 |阅读模式
为帮助公司客户更好的进行抓取和发布,完成特定任务,我们发布了火车浏览器开发版SDK。用户可以通过各种程序,使用命令行的方式调用火车浏览器的任务运行器,就可以得到浏览器运行完成后的结果。

SDK下载地地址:http://www.locoyposter.com/LpSDK.rar,下载后注意将最新版的火车浏览器解压到项目的Debug目录下,即可以测试使用。

该SDK中包含c#和Java版两种语言开发示例,文档中也包含使用说明文档。具体参数请看代码说明和参考C#.

开发者下载后,请打开默认的C#项目,查看各种参数,如有疑问,请回帖或群内提问。下边是C#的调用的主要方法。请使用visual studio 2008或更高版本打开。

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Diagnostics;

  5. namespace LpSDK
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             TaskConfig tc = new TaskConfig();
  12.             tc.TaskFile = AppDomain.CurrentDomain.BaseDirectory + "Projects\\testcmd.lp"; ;
  13.             tc.SKey = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(DateTime.Now.ToString("yyyyMMdd"), "MD5").ToLower().Substring(8, 16);
  14.             tc.LogFilePath = AppDomain.CurrentDomain.BaseDirectory + "test.txt";
  15.             tc.ResultFile = AppDomain.CurrentDomain.BaseDirectory + "result.xml";
  16.             tc.TaskName = "演示火车浏览器SDK的使用";
  17.             string app = AppDomain.CurrentDomain.BaseDirectory + "TasksRunner.exe";
  18.             tc.Varlist.Add("关键词", "改革");
  19.             if (System.IO.File.Exists(tc.LogFilePath)) System.IO.File.Delete(tc.LogFilePath);
  20.             if (System.IO.File.Exists(tc.ResultFile)) System.IO.File.Delete(tc.ResultFile);
  21.             string arg = tc.ToString();
  22.             ProcessStartInfo processStartInfo = new ProcessStartInfo();
  23.             processStartInfo.FileName = app;
  24.             processStartInfo.Arguments = arg;
  25.             Process process = Process.Start(processStartInfo);


  26.             while (process != null && !process.HasExited)
  27.             {
  28.                 System.Threading.Thread.Sleep(200);
  29.             }

  30.             //读取结果或日志进行分析,有些任务是不需要返回结果文件可以为空,通过其它方式判断是否成功。
  31.             if (System.IO.File.Exists(tc.ResultFile))
  32.             {
  33.                 System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
  34.                 doc.Load(tc.ResultFile);
  35.                 string title = doc.DocumentElement.SelectSingleNode("//String/标题").InnerText;
  36.                 string url = doc.DocumentElement.SelectSingleNode("//String/采集页网址").InnerText;
  37.                 Console.WriteLine(string.Format("标题:{0}\r\n网址:{1}", title, url));

  38.                 //<?xml version="1.0" encoding="utf-8"?>
  39.                 //<Root>
  40.                 //  <List name="ls">
  41.                 //    <value>http://news.qq.com/a/20140819/004539.htm?tu_biz=1.114.1.0</value>
  42.                 //    <value>http://news.qq.com/a/20140819/002046.htm?tu_biz=1.114.1.0</value>
  43.                 //    <value>http://news.qq.com/a/20140819/001181.htm?tu_biz=1.114.1.0</value>
  44.                 //    <value>http://news.qq.com/a/20140818/079323.htm?tu_biz=1.114.1.0</value>
  45.                 //    <value>http://news.qq.com/a/20140819/014417.htm?tu_biz=1.114.1.0</value>
  46.                 //    <value>http://news.qq.com/a/20140819/011585.htm?tu_biz=1.114.1.1</value>
  47.                 //    <value>http://news.qq.com/a/20140819/010341.htm?tu_biz=1.114.1.1</value>
  48.                 //    <value>http://news.qq.com/a/20140819/014565.htm?tu_biz=1.114.1.1</value>
  49.                 //  </List>
  50.                 //  <String>
  51.                 //    <va>
  52.                 //    </va>
  53.                 //  </String>
  54.                 //</Root>
  55.             }
  56.             else
  57.             {
  58.                 Console.WriteLine("运行失败,没有找到结果文件");
  59.             }
  60.             Console.ReadKey();
  61.         }
  62.     }
  63. }
复制代码


  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Xml;

  5. namespace LpSDK
  6. {
  7.     public class TaskConfig
  8.     {
  9.         /// <summary>
  10.         /// 任务运行名称
  11.         /// </summary>
  12.         public string TaskName = "";

  13.         /// <summary>
  14.         /// 任务脚本文件,不得为空
  15.         /// </summary>
  16.         public string TaskFile = "";

  17.         /// <summary>
  18.         /// 开发版SDK的Key
  19.         /// </summary>
  20.         public string SKey = "";

  21.         /// <summary>
  22.         /// 缓存文件目录,不指定系统自动创建
  23.         /// </summary>
  24.         public string CacheFiles = "";

  25.         /// <summary>
  26.         /// 浏览器窗口显示模式,0:默认大小,1:最小化,2:最大化
  27.         /// </summary>
  28.         public int WindowState = 0;

  29.         /// <summary>
  30.         /// 日志文件目录,空为不写日志
  31.         /// </summary>
  32.         public string LogFilePath = "";

  33.         /// <summary>
  34.         /// 返回的所有变量值保存的文件,为空不返回值
  35.         /// </summary>
  36.         public string ResultFile = "";

  37.         /// <summary>
  38.         /// 脚本运行完成后界面还显示多长时间,方便查看
  39.         /// </summary>
  40.         public int ShowTime = 0;

  41.         /// <summary>
  42.         /// 所有变量的键值对
  43.         /// </summary>
  44.         public Dictionary<string, string> Varlist = new Dictionary<string, string>();

  45.         /// <summary>
  46.         /// 将配置文件生成xml并urlencode处理
  47.         /// </summary>
  48.         /// <returns></returns>
  49.         public override string ToString()
  50.         {
  51.             if (!System.IO.File.Exists(TaskFile)) throw new Exception("脚本文件不存在");
  52.             if (string.IsNullOrEmpty(SKey)) throw new Exception("SKey不得为空");

  53.             System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
  54.             System.Xml.XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "utf-8", null);
  55.             doc.AppendChild(dec);
  56.             System.Xml.XmlElement root = doc.CreateElement("root");
  57.             if (!string.IsNullOrEmpty(TaskName)) root.SetAttribute("TaskName", TaskName);
  58.             root.SetAttribute("TaskFile", TaskFile);
  59.             root.SetAttribute("SKey", SKey);
  60.             if (!string.IsNullOrEmpty(CacheFiles)) root.SetAttribute("CacheFiles", CacheFiles);
  61.             root.SetAttribute("WindowState", WindowState.ToString());
  62.             if (!string.IsNullOrEmpty(LogFilePath)) root.SetAttribute("LogFilePath", LogFilePath);
  63.             if (!string.IsNullOrEmpty(ResultFile)) root.SetAttribute("ResultFile", ResultFile);
  64.             root.SetAttribute("ShowTime", ShowTime.ToString());

  65.             XmlNode varlist = doc.CreateNode(XmlNodeType.Element, "Varlist", "");
  66.             if (this.Varlist.Count > 0)
  67.             {
  68.                 foreach (KeyValuePair<string, string> kv in Varlist)
  69.                 {
  70.                     XmlNode node = doc.CreateNode(XmlNodeType.Element, kv.Key, "");
  71.                     node.InnerText = kv.Value;
  72.                     varlist.AppendChild(node);
  73.                 }
  74.             }
  75.             root.AppendChild(varlist);
  76.             doc.AppendChild(root);
  77.             string xml = doc.OuterXml;
  78.             /*
  79.             <?xml version="1.0" encoding="utf-8"?><root TaskFile="F:\LpSDK\bin\Debug\Projects\testcmd.lp" SKey="081c5f101bed6d44" WindowState="0" LogFilePath="F:\LpSDK\bin\Debug\test.txt" ResultFile="F:\LpSDK\bin\Debug\result.xml" ShowTime="0"><Varlist><关键词>改革</关键词></Varlist></root>
  80.              * */
  81.             return System.Web.HttpUtility.UrlEncode(xml);
  82.         }
  83.     }

  84. }
复制代码





回复

使用道具 举报

0

主题

1

帖子

184

积分

注册会员

Rank: 2

积分
184
发表于 2015-6-8 15:26:36 | 显示全部楼层
看过,的确不错。谢谢楼主
回复 支持 反对

使用道具 举报

1

主题

3

帖子

11

积分

新手上路

Rank: 1

积分
11
发表于 2015-9-27 22:34:17 | 显示全部楼层
不懂怎么用,有些高深阿
回复 支持 反对

使用道具 举报

0

主题

2

帖子

902

积分

高级会员

Rank: 4

积分
902
发表于 2020-10-30 05:40:08 | 显示全部楼层
能给出易语言的开发SDK和demo就好了
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|火车浏览器  

GMT+8, 2024-3-19 16:47 , Processed in 0.086584 second(s), 29 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表