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. javascript编程: JSON, Mapping, 回调

    使用 Javascript  编程, 组合使用 JSON 数据格式,Mapping 和回调技术, 可以产生很强的表达效果. 在实际工作中, 总会有数据汇总的需求. 比如说, 取得了多个 device ...

  2. Dynamics AX 2012 R3 Demo 安装与配置 - 配置安装环境 (Step 1)

    AX 2012 R3 发布后,Reinhard一直想体验一把,可是Reinhard所在的公司暂时不会升级到R3版本.这不,Reinhard就打算在个人电脑上安装下,可是安装的过程中,遇到了很多问题,R ...

  3. SpringMVC 手动控制事务提交

    描述 事务还是一个比较好的东东,有了这个,我们在做流程性的东西的时候,就会很好,很nice. 现在看看 SpringMVC 如何实现的,详细请看代码: 1.配置文件 applicationContex ...

  4. Java虚拟机学习(2):垃圾收集算法

    跟踪收集器 跟踪收集器采用的为集中式的管理方式,全局记录对象之间的引用状态,执行时从一些列GC  Roots的对象做为起点,从这些节点向下开始进行搜索所有的引用链,当一个对象到GC  Roots 没有 ...

  5. 【转】 Tomcat v7.0 Server at localhost was unable to start within 45

    转载地址:http://www.jsjtt.com/java/JavaWebkaifa/58.html Starting Tomcat v7.0 Server at localhost' has en ...

  6. libevent源码分析:bufferevent

    struct bufferevent定义在文件bufferevent_struct.h中. /** Shared implementation of a bufferevent. This type ...

  7. Android 编译时注解解析框架

    2.注解 说道注解,竟然还有各种分类,得,这记不住,我们从注解的作用来反推其分类,帮助大家记忆,然后举例强化大家的记忆,话说注解的作用: 1.标记一些信息,这么说可能太抽象,那么我说,你见过@Over ...

  8. javascript 面向对象(转)

    1.使用[]调用对象的属性和方法 function User() { this.age = 21; this.sex = "男?"; } var user = new User() ...

  9. CSS3的chapter1

    初学CSS3的第一天,虽然之前有接触过CSS,不过好像是CSS2,我也上网了解了一下CSS3,新增了很多强大的元素,也让我更有兴趣去学习了. CSS(Cascading Style Sheets) 层 ...

  10. EasyUI关于 numberbox,combobox,validatebox 的几个小问题

    在最近的项目中,首次使用到了 网页的一个布局框架——EasyUI,感觉这个框架特别牛,兼容性很不错,页面效果也挺不错,可是在使用标题上三个控件过程中遇到几个很奇特的问题,让我头疼不已,所以在此给广大I ...