修复抓取资讯报错bug问题

develop
old易 2024-07-09 10:34:50 +08:00
parent 43c0572015
commit a77c80d023
2 changed files with 12 additions and 8 deletions

View File

@ -52,8 +52,7 @@ namespace New_College.Tasks
ProvinceCode = "370000",
CreateId = 1,
CreateTime = c.pubtime,
// Detail = c.detail,
Detail = c.detail,
CoverImg = "https://static-data.ycymedu.com/static/newstop.png",
OrderSort = 0,
IsDelete = false,

View File

@ -1,5 +1,6 @@
using Aliyun.OSS.Model;
using HtmlAgilityPack;
using New_College.Common.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
@ -26,18 +27,22 @@ namespace New_College.Tasks
}
listurls.ForEach(url =>
{
var doc = webClient.Load(url);
var inntertitle = doc.DocumentNode.SelectSingleNode("//*[@id=\"form1\"]/div[6]/div[2]/h3").InnerText;
var author = doc.DocumentNode.SelectSingleNode("//*[@id=\"form1\"]/div[6]/div[2]/em").InnerText.Split("作者:")[1].Split(" ")[0];
var createtime = doc.DocumentNode.SelectSingleNode("//*[@id=\"form1\"]/div[6]/div[2]/em").InnerText.Split("发布时间:")[1];
var innerhtml = doc.DocumentNode.SelectSingleNode("//*[@id=\"form1\"]/div[6]/div[2]/div").InnerHtml;
list.Add(new NewsModels()
if (!HtmlHelper.ReplaceHtmlTag(innerhtml).Contains("浏览器"))
{
title = inntertitle,
author = author,
pubtime = Convert.ToDateTime(createtime),
detail = innerhtml.Replace("src=\"", "src=\"https://www.sdzk.cn").Replace("href=\"", "href=\"https://www.sdzk.cn")
});
list.Add(new NewsModels()
{
title = inntertitle,
author = author,
pubtime = Convert.ToDateTime(createtime),
detail = innerhtml.Replace("src=\"", "src=\"https://www.sdzk.cn").Replace("href=\"", "href=\"https://www.sdzk.cn")
});
}
});
return list;
}