1. Нам нужен CefSharp.OffScreen
2. Создаем класс BrokenCoreParser
3. Пихает в класс BrokenCoreParser код ниже
4. Создаем класс BrokeCoreParserResponce
5. Пихает в класс BrokeCoreParserResponce код ниже
2. Создаем класс BrokenCoreParser
3. Пихает в класс BrokenCoreParser код ниже
C#:
public class BrokeCoreParser
{
public BrokeCoreParserResponce Parse(string link)
{
BrokeCoreParserResponce brokeCoreParserResponce = new BrokeCoreParserResponce();
CefSharp.OffScreen.ChromiumWebBrowser chromiumWebBrowser = new CefSharp.OffScreen.ChromiumWebBrowser();
bool load = false;
Task<bool> waiter = new Task<bool>(() =>
{
while (load == false)
{
}
return true;
});
chromiumWebBrowser.LoadingStateChanged += async (sender, args) =>
{
//Wait for the Page to finish loading
if (args.IsLoading == false)
{
try
{
JavascriptResponse responseNickname = await chromiumWebBrowser.EvaluateScriptAsync("document.getElementsByClassName('username')[0].innerText");
brokeCoreParserResponce.Nickname = responseNickname.Result.ToString();
JavascriptResponse responseStaff = await chromiumWebBrowser.EvaluateScriptAsync("document.getElementsByClassName('uB')[0].innerText");
brokeCoreParserResponce.Staff = responseStaff.Result.ToString();
JavascriptResponse responseMessages = await chromiumWebBrowser.EvaluateScriptAsync("document.getElementsByClassName('pairs pairs--rows pairs--rows--centered')[0].outerText");
brokeCoreParserResponce.Messages = Convert.ToInt32(responseMessages.Result.ToString().Split('\n')[1]);
try
{
JavascriptResponse responseResources = await chromiumWebBrowser.EvaluateScriptAsync("document.getElementsByClassName('menu-fauxLinkRow-linkRow u-concealed')[0].innerText");
brokeCoreParserResponce.Resources = Convert.ToInt32(responseResources.Result.ToString());
}
catch { brokeCoreParserResponce.Resources = 0; }
if (brokeCoreParserResponce.Resources == 0)
{
JavascriptResponse responseReactions = await chromiumWebBrowser.EvaluateScriptAsync("document.getElementsByClassName('pairs pairs--rows pairs--rows--centered')[1].innerText");
brokeCoreParserResponce.Reactions = Convert.ToInt32(responseReactions.Result.ToString().Split('\n')[1]);
}
else
{
JavascriptResponse responseReactions = await chromiumWebBrowser.EvaluateScriptAsync("document.getElementsByClassName('pairs pairs--rows pairs--rows--centered')[2].innerText");
brokeCoreParserResponce.Reactions = Convert.ToInt32(responseReactions.Result.ToString().Split('\n')[1]);
}
brokeCoreParserResponce.Valid = true;
}
catch
{
brokeCoreParserResponce.Valid = false;
}
load = true;
}
};
waiter.Start();
chromiumWebBrowser.Load(link);
bool temp = waiter.Result;
return brokeCoreParserResponce;
}
}
5. Пихает в класс BrokeCoreParserResponce код ниже
C#:
public class BrokeCoreParserResponce
{
public bool Valid;
public string Nickname;
public string Staff;
public int Messages;
public int Resources;
public int Reactions;
}
C#:
BrokeCoreParser brokeCoreParser = new BrokeCoreParser();
BrokeCoreParserResponce responce = brokeCoreParser.Parse("https://brokencore.club/neki_play/");
if (responce.Valid)
{
Console.WriteLine("Ник: " + responce.Nickname);
if (responce.Staff != "")
{
Console.WriteLine("Стафф: " + responce.Staff);
}
Console.WriteLine("Сообшений: " + responce.Messages);
Console.WriteLine("Ресурсов: " + responce.Resources);
Console.WriteLine("Реакций: " + responce.Reactions);
}
else
{
Console.WriteLine("Пользователь не найден");
}
Последнее редактирование: