I'm trying to get text but I'm always getting NullReferenceException error. I'm getting crazy. It worked for a moment but I've started to get this error again. I'll just get post title's.
I've tried to change my XPath. I tried different XPath's.
private void button1_Click(object sender, EventArgs e)
{
listView1.Items.Clear();
for (int i = 4; i < 9; i++)
{
VeriAl(Url: "https://cracked.to/Forum-Combolists?sortby=started&order=desc&datecut=9999&prefix=0", XPath: "//table[@class='tborder clear']//tr[" + i + "]//td[2]//div[1]//span[1]//span[1]//a", tag: "title",CikanSonuc: listView1);
}
}
public void VeriAl (String Url, String XPath, String tag,ListView CikanSonuc)
{
try
{
url = new Uri(Url);
}
catch (UriFormatException)
{
if (MessageBox.Show(text: "UriFormatException", caption: "Hata", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error) == DialogResult.OK)
{
}
}
catch (ArgumentNullException)
{
if (MessageBox.Show(text: "ArgumentNullException", caption: "Hata", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error) == DialogResult.OK)
{
}
}
WebClient client = new WebClient();
try
{
html = client.DownloadString(url);
}
catch (WebException)
{
if (MessageBox.Show(text: "WebException", caption: "Hata", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error) == DialogResult.OK)
{
}
}
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(html);
try
{
CikanSonuc.Items.Add(doc.DocumentNode.SelectSingleNode(XPath).Attributes[tag].Value);
}
catch (NullReferenceException)
{
if (MessageBox.Show(text: "NullReferenceException", caption: "Hata", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error) == DialogResult.OK)
{
}
}