I can't do anything using XPath, I don't know why this isn't working? I tried many ways still I ended up with NullReferenceException error. I really need your help :/
You can look at the code full size here (https://notepad.pw/share/lyugaxmg)
I tried this;
- I take with ChroPath API but this does not work.
- I tried to right-click or F12 and again right click>copy>copy XPath but this didn't work again.
I tried so many ways, can u help me? Maybe there is a problem with my code, I don't know.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.IO;
using HtmlAgilityPack;
namespace InternerVeriCekme
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public string html;
public Uri url;
public void VeriAl(string Url,string XPath,TextBox cikansonuc)
{
try
{
url = new Uri(Url);
}
catch (UriFormatException)
{
if (MessageBox.Show("Hatalı URL", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error) == DialogResult.OK) { };
}
catch(ArgumentNullException)
{
if (MessageBox.Show("Hatalı URL", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error) == DialogResult.OK) { };
}
WebClient client = new WebClient();
client.Encoding = Encoding.UTF8;
try
{
html = client.DownloadString(url);
}
catch (WebException)
{
if (MessageBox.Show("Hatalı URL", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error) == DialogResult.OK) { };
}
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(html);
try
{
textBox1.Text = doc.DocumentNode.SelectSingleNode(XPath).InnerText;
}
catch (NullReferenceException)
{
if (MessageBox.Show("Hatalı xpath", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error) == DialogResult.OK) { };
}
}
private void button1_Click(object sender, EventArgs e)
{
if (bunifuMaterialTextbox1.Text != "")
{
VeriAl("https://www.instagram.com/lunaslol/", "/html[1]/body[1]/div[1]/section[1]/main[1]/div[1]/div[1]/h1[1]", textBox1);
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}