Skip to content

Commit

Permalink
修复登录信息解析,在解析失败时生成调试信息
Browse files Browse the repository at this point in the history
  • Loading branch information
fffonion committed Oct 30, 2023
1 parent 9fe0ae1 commit 67cc9c1
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
40 changes: 37 additions & 3 deletions Novel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using HtmlAgilityPack;
using System.Text.RegularExpressions;
using Newtonsoft.Json.Linq;
using System.IO.Compression;

namespace jjget
{
Expand All @@ -28,6 +29,7 @@ class Novel
private string cookiestr;
public string userDetail;
public bool hasLogin = false;
private string lastParsedHTML;
private WebProxy proxy = null;
private Action<string, Color> setProgressDelegate;
private Action<byte[]> setVerifyCodeDelegate;
Expand Down Expand Up @@ -269,14 +271,15 @@ private void getUserDetail()
HtmlNode root = hd.DocumentNode;
HtmlNode tb = root.SelectSingleNode("//table[@bgcolor='#009900']");
bool isWriter = false;
var detailTr = tb.SelectSingleNode("./tr[1]//font[@class='readerid']");
var detailTr = tb.SelectSingleNode(".//tr//font[@class='readerid']");
if (detailTr == null)
{
detailTr = tb.SelectSingleNode("./tr[1]//div[1]");
isWriter = true;
}
userDetail = "已登录 ID: " + detailTr.InnerText.Trim();
string _nick = tb.SelectSingleNode("./tr[" + (isWriter? "3" : "2") + "]/td[2]/div").InnerText;
userDetail = "已登录 ID: " + (detailTr != null ? detailTr.InnerText.Trim(): "未知ID");
var _nickInput = tb.SelectSingleNode("//input[@name='birthday']");
string _nick = _nickInput == null ? _nickInput.GetAttributeValue("value", "未知昵称") : "未知昵称";
if (_nick != "您还没有设置昵称")
userDetail += " " + _nick;
// disable email for now
Expand Down Expand Up @@ -413,6 +416,7 @@ public Chapter getSingleChapter(int chapter)
//StreamReader sFile = new StreamReader(fs);
//string html = sFile.ReadToEnd();
//setPrompt("分析中……", Color.Orange);
lastParsedHTML = html;
HtmlAgilityPack.HtmlDocument hd = new HtmlAgilityPack.HtmlDocument();
hd.LoadHtml(html);
HtmlNodeCollection hnc;
Expand Down Expand Up @@ -472,6 +476,7 @@ public Chapter getSingleChapter(int chapter)
{
context[key] = getInputLabelValue(root, key);
}
// jsid 就是用户ID
Regex jsidRegex = new Regex(@"//my\.jjwxc\.net/backend/favorite\.php\?jsid=(\d+)");
var match = jsidRegex.Match(root.InnerHtml);
if(!match.Success)
Expand Down Expand Up @@ -634,5 +639,34 @@ public FontDecoder getFontDecoder()
{
return fontDecoder;
}

public void writeDebugInfo(string path)
{
using (var memoryStream = new MemoryStream())
{
using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
{
using (var entryStream = archive.CreateEntry("singlePage.html").Open())
using (var streamWriter = new StreamWriter(entryStream))
{
streamWriter.Write(lastParsedHTML);
}

using (var entryStream = archive.CreateEntry("config.txt").Open())
using (var streamWriter = new StreamWriter(entryStream))
{
streamWriter.WriteLine("novelid: " + novelid);
streamWriter.WriteLine("useMobileEdition: " + useMobileEdition);
streamWriter.WriteLine("hasLogin: " + hasLogin);
}
}

using (var fileStream = new FileStream(path, FileMode.Create))
{
memoryStream.Seek(0, SeekOrigin.Begin);
memoryStream.CopyTo(fileStream);
}
}
}
}
}
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.4")]
[assembly: AssemblyFileVersion("1.4.4")]
[assembly: AssemblyVersion("1.4.5")]
[assembly: AssemblyFileVersion("1.4.5")]
4 changes: 3 additions & 1 deletion frmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,14 @@ private void button1_Click(object sender, EventArgs e)
break;
}
}
if (terminate)
{
this.Invoke(new Action(() =>
{
btnStart.Text = "开始";
setPrompt(("已中断下载"), Color.Red);
novel.writeDebugInfo("jjdebug.zip");
setPrompt(("调试信息已经保存到jjdebug.zip,虽然其中不包含登录数据,但请勿公开分享"), Color.Red);
}));
return;
}
Expand Down
1 change: 1 addition & 0 deletions jjget.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
Expand Down

0 comments on commit 67cc9c1

Please sign in to comment.