I want to convert the base64 data I have to html type, when I do this conversion, the html file comes out as corrupted and I cannot do scraping with Agility pack. But when I do the conversion manually with an online tool on the internet, the html file comes up properly and I can scrape. My codes are as follows. Please help
string base64Data = "//Base64 in here";
byte[] decodedBytes = Convert.FromBase64String(base64Data);
string decodedText = Encoding.UTF8.GetString(decodedBytes);
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
string filePath = Path.Combine(desktopPath, "decoded_data.html");
File.WriteAllText(filePath, decodedText);
filePath = Path.Combine(desktopPath, "decoded_data.html");
HtmlWeb htmlWeb = new HtmlWeb();
HtmlDocument doc = htmlWeb.Load(filePath);
HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes("//body//table[1]//tr[2]//td[2]//tr[3]//td[2]");
foreach (HtmlNode node in nodes)
{
Console.WriteLine(node.InnerText);
}
Naimish MakwanaPosted Feb 2, 2023, 11:32 AM
Hello MEHMET,
PFB working example.
Please accept answer if it's useful.
Thanks
Naimish Makwana
Mehmet KentPosted Feb 2, 2023, 11:08 AM
html file looking like this
Naimish MakwanaPosted Feb 2, 2023, 10:51 AM
Hello MEHMET,
You can use like below.
Working example:
Thanks
Naimish Makwana
Naimish MakwanaPosted Feb 2, 2023, 10:42 AM
Hello MEHMET
It is possible that the base64 data is not properly decoded or not in the expected format that Agility Pack is expecting.
Can you share your base64 string?
Thanks