Skip to content

Commit

Permalink
修复解析CSS中的内容,修复非V章解析,修复cookie登录
Browse files Browse the repository at this point in the history
  • Loading branch information
fffonion committed Jul 27, 2023
1 parent 7199623 commit 2211650
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
32 changes: 27 additions & 5 deletions Novel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ private void getUserDetail()
string _nick = tb.SelectSingleNode("./tr[" + (isWriter? "3" : "2") + "]/td[2]/div").InnerText;
if (_nick != "您还没有设置昵称")
userDetail += " " + _nick;
userDetail += " "+tb.SelectSingleNode("./tr[" + (isWriter ? "8" : "7") + "]//div/span").InnerText;
// disable email for now
// userDetail += " "+tb.SelectSingleNode("./tr[" + (isWriter ? "8" : "7") + "]//td[@id='emailtd']/text()").InnerText;
}

private string stripEmpty(string input)
Expand Down Expand Up @@ -430,7 +431,7 @@ public Chapter getSingleChapter(int chapter)
}
else
{
HtmlNode novelnode = root.SelectSingleNode("//div[contains(@class,'noveltext')]");
HtmlNode novelnode = root.SelectSingleNode("//div[@class='novelbody']/div");
if(novelnode == null)
{
throw new Exception("章节" + chapter + (isVip ? "是VIP章节,请登陆ww":"解析失败"));
Expand Down Expand Up @@ -491,8 +492,31 @@ public Chapter getSingleChapter(int chapter)
mainbody = novelnode.InnerHtml;
}

var styles = "";
foreach (var e in root.SelectNodes("//style"))
{
styles += e.InnerText;
}
var cssRegexStr = @"[^{]+{\s*content\s*:\s*['""](.*?)['""]\s*;*\s*}";
mainbody = Regex.Replace(mainbody, @"<span\s+class='([^']+)'>([^<]+)</span>", m => {
var clsName = m.Groups[1].Value;
var text = m.Groups[2].Value;
var mb = Regex.Match(styles, clsName + ":before" + cssRegexStr);
if(mb.Success)
{
text = mb.Groups[1].Value + text;
}
var ma = Regex.Match(styles, clsName + ":after" + cssRegexStr);
if (ma.Success)
{
text += ma.Groups[1].Value;
}
return text;
});


mainbody = HtmlEntity.DeEntitize(
mainbody.Replace("<br>", "\r\n").Replace("</br>", "\r\n"));
mainbody.Replace("<br>", "\r\n").Replace("</br>", "\r\n").Replace("&zwnj;", ""));

if (fontName != "")
{
Expand All @@ -501,8 +525,6 @@ public Chapter getSingleChapter(int chapter)
chpt.content = "  " +
mainbody.Replace("@无限好文,尽在晋江文学城", "").Replace("@无限好文,尽晋江文学城","").Trim() +
chpt.content;


}
chpt.chapterIndex = chapter;
setPrompt("章节"+chapter+"("+chpt.title+")已完成");
Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.4.2")]
[assembly: AssemblyFileVersion("1.4.2")]
[assembly: AssemblyVersion("1.4.3")]
[assembly: AssemblyFileVersion("1.4.3")]
4 changes: 2 additions & 2 deletions jjget.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<PackageReference Include="HtmlAgilityPack">
<Version>1.11.46</Version>
<Version>1.11.50</Version>
</PackageReference>
<PackageReference Include="ILRepack">
<Version>2.0.18</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>13.0.2</Version>
<Version>13.0.3</Version>
</PackageReference>
</ItemGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down

0 comments on commit 2211650

Please sign in to comment.