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. js计时器方法 setInterval(),setTimeout()

    window.setInterval() 周期性地调用一个函数(function)或者执行一段代码. var intervalID = window.setInterval(func, delay[, ...

  2. iOS 开发笔记-AFNetWorking https SSL认证

    一般来讲如果app用了web service , 我们需要防止数据嗅探来保证数据安全.通常的做法是用ssl来连接以防止数据抓包和嗅探 其实这么做的话还是不够的 . 我们还需要防止中间人攻击(不明白的自 ...

  3. POJ 2420:A Star not a Tree?

    原文链接:https://www.dreamwings.cn/poj2420/2838.html A Star not a Tree? Time Limit: 1000MS   Memory Limi ...

  4. MySql + EF6 + .Net Core

    2016年8月17日01:21:29 更新:这里介绍一下一个开源的 EF Core 的 MySQL 组件 [MySQL for .NET Core - Pomelo 扩展包系列][http://www ...

  5. [CCF] ISBN号码检测

    CCF ISBN号码检测 题目概述 每一本正式出版的图书都有一个ISBN号码与之对应,ISBN码包括9位数字.1位识别码和3位分隔符,其规定格式如"x-xxx-xxxxx-x",其 ...

  6. IntelliJ IDEA使用(3)——IDEA连接Git

    摘要: Intellij IDEA作为最强大智能的IDE,内部已经集成了Git的功能,所以不用安装插件,连接Git@OSC也非常容易 首先安装git for windows 推荐使用这个:http:/ ...

  7. Less 使用指南

    简而言之 Less是为了简化css http://less.bootcss.com/features/ 以上链接是Less中文网站,里面有对Less的详细介绍. 一下写在使用中遇到的问题: 1.下载L ...

  8. Android 获取全部应用

      package com.lvshandian.menshen.download;import android.content.Context;import android.content.Inte ...

  9. 第十四天 jni 的使用

    1. ndk 环境 2.jni hello 程序. 3.javah 生成头文件. 4.java 和c 之间数据传递. 5.C语言回调java 代码 通过反射.得到字节码,得到方法...

  10. 《BI那点儿事》数据流转换——逆透视转换

    逆透视转换将来自单个记录中多个列的值扩展为单个列中具有同样值的多个记录,使得非规范的数据集成为较规范的版本.例如,每个客户在列出客户名的数据集中各占一行,在该行的各列中显示购买的产品和数量.逆透视转换 ...