So I have a method that returns every html download link in a separate html file I have in my folder. unfortunately it only returns 1 of the few I have.
Here is the method
private string GetHTMLDownloadLinks(string url, char SplitChhar, string serach, int index)
{
//Initiates a new instance of WEbClient class
WebClient WC = new WebClient();
try
{
//Initiates a new stream instance with a url
Stream stream = WC.OpenRead(url);
//Initiates a streamreader to read the url parsed
StreamReader reader = new StreamReader(stream);
string line;
//Loops through the specifed url's html source
//and read every line
while ((line = reader.ReadLine()) != null)
{
//If it finds the specified character that the user passed
if (line.IndexOf(serach) != -1)
{
//it adds it to the parts variable
string[] parts = line.Split(SplitChhar);
//Returns the index of the found
return parts[index];
}
}
}
catch (Exception Ex)
{
MessageBox.Show($"There seems to be a problem: {Ex}", "I am an error", MessageBoxButton.OKCancel, MessageBoxImage.Error);
}
return "" + "\n";
}
I suspect the error is in the loop because it only loops until it find the first one and doesn't continue
This is how I (invoke?) start the method
TxtBox_WebInfo.Text += GetHTMLDownloadLinks(@"Link to the HTML file", '"', "download", 1);
Edit Here is the body of the HTML its the only place that has any kind of link
<body>
<div>
<h1>Download indexer for *app name*</h1>
<img src="https://img2.cgtrader.com/items/56921/04705862f7/white-teapot-3d-model-obj-blend-mtl.png" />
<a href="https://dl0.png" download>Download this image</a>
<a href="https://dl1.png" download>asdg</a>
<a href="https://dl2.png" download>asgsdg</a>
</div>
</body>
It only returns the first one.
Tell me if anything is missing