using AnfleCrawler.Common;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks; namespace AnfleCrawler.DataAnalyzer
{
internal class GFT_News : AnalyzerBase
{
public override void Init(PageCrawler crawler)
{
// var pHandler = new PageContentHandler()
// {
// Url = new Uri("http://admin.gofangtong.com/Login.aspx"),
// CrossLoad = (arg, xDom) =>
// {
// if (arg.IsRedirect)
// {
// arg.IsRedirect = false;
// return;
// }
// arg.IsRedirect = true;
// var input = xDom.GetElementById("txtusername");
// input.SetAttribute("value", "admin");
// input = xDom.GetElementById("txtuserpass");
// input.SetAttribute("value", "123456");
// var btn = xDom.GetElementById("btnlogin");
// btn.InvokeMember("click");
// }
// };
// Crawler.Lander.GetDocument(pHandler); //crawler.PushUrl(new System.Net.StringPatternGenerator("http://webapi.anfle.com/BMLF/BmlfList?page=[1-75]&rows=50&sort=PublishDate&order=desc"), 0);
base.Init(crawler);
} protected override void AnalyzeInternal(PageLandEntity current)
{
var lander = Crawler.Lander;
var pHandler = CreateContentHandler(current); var dom = lander.GetDocument(pHandler);
string text = dom.DocumentNode.InnerText;
//App.LogInfo("GFT:\r\n\r\n{0}", text);
var json = JObject.Parse(text);
var client = new HttpClient();
client.SendReceiveTimeout = int.MaxValue;
foreach (var item in json["rows"])
{
try
{
string content = System.Web.HttpUtility.UrlEncode(item.Value<string>("CONTENT"));
client.SetRequest(new Uri("http://webapi.anfle.com/BMLF/Match"));
client.Form["content"] = content;
var matchtext = client.GetResponse().GetResponseText();
var mjson = JObject.Parse(matchtext);
var mset = (JArray)mjson["Message"];
var str = new StringBuilder();
var configs = new KeyValuePair<string, string>[]
{
new KeyValuePair<string, string>("CITY_NAME","城市"),
new KeyValuePair<string, string>("STANDARD_REGION","区域"),
new KeyValuePair<string, string>("SHORT_NAME_CHS","企业"),
new KeyValuePair<string, string>("XIANGMUMINGCHENG","项目"),
};
for (int i = ; i < mset.Count; i++)
{
if (mset[i] == null)
{
continue;
}
var c = configs[i];
var thenSet = mset[i].Select(p =>
{
string ext = string.Empty;
if (i == && p["CITY_NAME"] != null)
{
ext = p.Value<string>("CITY_NAME") + "-";
}
return ext + p.Value<string>(c.Key) + "|" + c.Value;
});
if (!thenSet.Any())
{
continue;
}
str.Append(",").Append(string.Join(",", thenSet));
}
string rowid = item.Value<string>("ROWID");
if (str.Length == )
{
Crawler.OutWrite("Skip Empty {0}", rowid);
continue;
} client.SetRequest(new Uri("http://webapi.anfle.com/BMLF/Save"));
client.Form["isModify"] = "true";
client.Form["rowId"] = rowid;
client.Form["val"] = str.ToString();
client.Form["kind"] = item.Value<string>("KIND");
client.Form["title"] = item.Value<string>("TITLE");
client.Form["source"] = item.Value<string>("SOURCE");
client.Form["date"] = item.Value<string>("PUBLISHDATE");
//client.Form["content"] = content;
client.Form["state"] = Convert.ToInt16(Convert.ToBoolean(item.Value<string>("STATE"))).ToString();
string ret = client.GetResponse().GetResponseText();
Crawler.OutWrite("Match OK {0} {1}", rowid, ret);
}
catch (Exception ex)
{
Crawler.OutWrite("Error {0}", ex.Message);
App.LogError(ex, "GFT");
}
}
}
}
}

GFT_News Auto的更多相关文章

  1. C++11特性——变量部分(using类型别名、constexpr常量表达式、auto类型推断、nullptr空指针等)

    #include <iostream> using namespace std; int main() { using cullptr = const unsigned long long ...

  2. overflow:hidden与margin:0 auto之间的冲突

    相对于父容器水平居中的代码margin:0 auto与overflow:hidden之间存在冲突.当这两个属性同时应用在一个DIV上时,在chrome浏览器中将无法居中.至于为啥我也不明白.

  3. Android Auto开发之一《开始学习Auto 》

    共同学习,共同进步, 转载请注明出处.欢迎微信交流:sfssqs,申请注明"Android Car"字样 ================= =================== ...

  4. width:100%;与width:auto;的区别

    <div> <p>1111</p> </div> div{ width:980px; background-color: #ccc; height:30 ...

  5. SQl 2005 For XMl 简单查询(Raw,Auto,Path模式)(1)

    很多人对Xpath可能比较熟悉,但不知道有没有直接操作过数据库,我们都知道 在Sql2005里公支持的几种查询有Raw,Auto模式,页并没有Path和Elements用法等,如果在2000里使用过 ...

  6. margin:0 auto;不居中

    margin:0 auto:不居中可能有以下两个的原因; 1.没有设置宽度<div style="margin:0 auto;"></div>看看上面的代码 ...

  7. 初学C++ 之 auto关键字(IDE:VS2013)

    /*使用auto关键字,需要先赋初值,auto关键字是会根据初值来判断类型*/ auto i = ; auto j = ; cout << "auto i = 5" & ...

  8. C++11 - 类型推导auto关键字

    在C++11中,auto关键字被作为类型自动类型推导关键字 (1)基本用法 C++98:类型 变量名 = 初值;   int i = 10; C++11:auto 变量名 = 初值;  auto i ...

  9. 为什么 "auto a = 1;" 在C语言中可以编译通过?

    参照:这里 这让我想起之前看的一部书, int i; 其实是等价与 auto int i; 表示为局部变量 这应该与static是相对的吧?

随机推荐

  1. es5.0 head插件安装

    1. 在 elasticsearch.yml 文件增加配置http.cors.enabled: truehttp.cors.allow-origin: "*"2. 下载插件git ...

  2. calico docker 应用实例

    在上一篇文章<quay.io/coreos/etcd 基于Docker镜像的集群搭建>中,介绍了ETCD集群的搭建.在此基础上,我们进一步实践calico docker的应用. PaaS ...

  3. CentOS 安装Zookeeper-3.4.6 单节点

    Dubbo 建议使用 Zookeeper 作为服务的注册中心. 注册中心服务器(192.168.3.71)配置,安装 Zookeeper: 1. 修改操作系统的/etc/hosts 文件中添加: #  ...

  4. Android属性动画完全解析(下)

    转载:http://blog.csdn.net/guolin_blog/article/details/44171115 大家好,欢迎继续回到Android属性动画完全解析.在上一篇文章当中我们学习了 ...

  5. 初学画布canvas的chapter2

    文本 1.字体属性 context.font = [css font property] ——使用CSS规范,语法跟CSS字体速记符号一致 ——line-height无效,并永远忽略 Context. ...

  6. DAL、DAO、ORM、Active Record辨析

    转自:http://blog.csdn.net/suiye/article/details/7824943 模型 Model 模型是MVC中的概念,指的是读取数据和改变数据的操作(业务逻辑).一开始我 ...

  7. 逻辑操作符---Lua: and,or,not 对比 C++:&&,||,!

    lua中有三个逻辑操作符:and,or,not(逻辑与,逻辑或,逻辑非),同样c++也有类似的三个逻辑操作符:&&,||,!(逻辑与,逻辑或,逻辑非).他们的运算对象就是真和假.lua ...

  8. 滚动RollUp、压缩

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  9. NSUrl的打印

    1转自 http://my.oschina.net/wangdk/blog/165554: NSURL *url = [NSURL URLWithString:@"http://www.ba ...

  10. 个推,手机推送api的使用

    个推的作用:可以为手机端的app使用者推送消息,而不是通过手机上的app对用户发送消息.所以用户是被动的接收信息.当然不只是只有对用户弹出窗口的这种方式,也可以把信息推送给app,让app决定对用户实 ...