using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.IO;
using
System.Net;
using
System.Threading.Tasks;
using
HtmlAgilityPack;
using
Newtonsoft.Json.Linq;
using
System.Text.RegularExpressions;
namespace
Ws_Jx
{
public
class
Ws
{
HtmlDocument Doc;
JObject Json;
public
Ws(
string
url)
{
GetUrl(
ref
url);
GetHtml(
ref
url);
FromatJson();
////构造函数
}
public
void
GetUrl(
ref
string
txt)
{
txt = txt.Substring(txt.IndexOf(
">>"
) + 2);
}
public
void
GetHtml(
ref
string
url)
{
var
Beg = (HttpWebRequest)WebRequest.Create(url);
Beg.AllowAutoRedirect =
false
;
Beg.UserAgent =
"Mozilla/5.0 (Linux; Android 6.0.1; Moto G (4)) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Mobile Safari/537.36"
;
var
Ret = (HttpWebResponse)Beg.GetResponse();
var
Read =
new
StreamReader(Ret.GetResponseStream(), Encoding.UTF8);
string
text = Read.ReadToEnd();
Doc =
new
HtmlDocument();
Doc.LoadHtml(text);
}
public
void
FromatJson()
{
string
json = Doc.DocumentNode.SelectSingleNode(
"//body/script[1]"
).InnerText.Substring(30).Replace(
"; } catch (err) { console.error('[Vise] fail to read initState.'); }"
,
""
);
Json = JObject.Parse(json);
}
public
string
GetCreateTime()
{
DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(
new
DateTime(1970, 1, 1));
return
startTime.AddSeconds(Convert.ToInt64(Json[
"feedsList"
][0][
"poster"
][
"createtime"
])).ToString(
"yyy-MM-dd hh:mm:ss"
);
}
public
string
GetAuthorName()
{
return
Json[
"feedsList"
][0][
"poster"
][
"nick"
].ToString();
}
public
string
GetAuthorHeadImage()
{
return
Regex.Unescape(Json[
"feedsList"
][0][
"poster"
][
"avatar"
].ToString());
}
public
string
GetHeightCover()
{
return
Regex.Unescape(Json[
"feedsList"
][0][
"images"
][0][
"url"
].ToString());
}
public
string
GetLowerCover()
{
return
Regex.Unescape(Json[
"feedsList"
][0][
"images"
][1][
"url"
].ToString());
}
public
string
GetLinkCount()
{
return
Regex.Unescape(Json[
"feedsList"
][0][
"dingCount"
].ToString());
}
public
string
GetCommentCount()
{
return
Regex.Unescape(Json[
"feedsList"
][0][
"totalCommentNum"
].ToString());
}
public
string
GetPlayNum()
{
return
Regex.Unescape(Json[
"feedsList"
][0][
"playNum"
].ToString());
}
public
string
GetMp4()
{
return
Regex.Unescape(Json[
"feedsList"
][0][
"videoUrl"
].ToString());
}
public
string
GetTitle()
{
return
Regex.Unescape(Json[
"feedsList"
][0][
"shareInfo"
][
"bodyMap"
][
"0"
][
"title"
].ToString());
}
}
}