采集网址:https://www.taoguba.com.cn/Article/2523033/1
需采集内容:
使用HtmlAgilityPack
时间xpath:
1、/html/body//span[contains(concat(' ', normalize-space(@class), ' '),' p_tatime ')]
2、//*[@id='new_wrap_container']/DIV[1]/DIV[2]/SPAN[2]
3、//SPAN[@class='p_tatime']
用上述xpath使用谷歌浏览器的xpath helper插件都可以采集到信息,但C#采集到的html都无法采集到时间。
请问哪位可以给个demo,C#实现的,能采集到标红的时间及文字内容
使用浏览器得到的xpath 中有一条为//SPAN[@class='p_tatime'],
该路径无法采集到时间信息,改为//span[@class='p_tatime']_可正确采集时间信息。
所以浏览器得到的xpath有时需要修改。
另外特别感谢:贵阳挖掘机马善福
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Text.RegularExpressions;
namespace Q769122
{
class Program
{
static void Main(string[] args)
{
WebClient wc = new WebClient();
var html = wc.DownloadData("https://www.taoguba.com.cn/Article/2523033/1");
var date = Regex.Match(Encoding.UTF8.GetString(html), @"\d{4}\-\d{2}-\d{2}\s\d{2}:\d{2}").Value;
var slice = Regex.Match(Encoding.UTF8.GetString(html), @"(?is)(?<=\<\!\-\-\s主贴内容开始\s\-\-\>).*(?=\<\!\-\-\s主贴内容结束\s\-\-\>)").Value;
Console.WriteLine(date);
Console.WriteLine(slice);
}
}
}
2019-07-14 08:09
<div class="p_coten" id='first'
style="">
<b>确定自己的模式------
选股自己要的股------判断真假涨----下单试错-----对(错)-----加仓(止损)----自己
模式的顶部----出货。</b><br/> <b>不要用
接力的模式,选套利的股,不要用套利的股,用来接力。</b><br/> &nb
sp; <b>先弄明白自己的模式,在找相关知识去选股。</b><br/> &
nbsp; <b>不要整天,搞什么道什么术,云里雾里。搞自己
很NB一样,学费交多了自然就知道坑。</b>
<!-- 投票选项开始 -->
<div style="width: 100%;
">
</div>
<!-- 投票选项结束 -->
</div>
Press any key to continue . . .