Click here to Skip to main content
15,887,867 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, I am facing a problem while creating a project that scraps data from some random website. My problem is I can't get any result after entering the following code. Please, help me to correct my code.


NOTE:- I want to see scrap data in the listbox. but can't see. Please, suggest the appropriate answer. Thanks.

What I have tried:

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 HtmlAgilityPack;
using System.Net;



namespace Project_1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            ServicePointManager.Expect100Continue = true;
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string path="/html/body/div[1]/div/div[3]/div/div[2]/div[1]/div[1]/div[2]";
            HtmlWeb myweb = new HtmlWeb();

           HtmlAgilityPack.HtmlDocument doc = myweb.Load("https://www.practo.com/jamnagar/doctors");

           var HeaderNames =( doc.DocumentNode.SelectNodes(path));

           if (HeaderNames != null)
           {
               var mylist = HeaderNames.ToList();



               foreach (var item in mylist)
                   if (item != null)
                   {
                       listBox1.Items.Add(item);
                   }

           }
        }
    }
}
Posted
Updated 30-Mar-22 1:22am
v2
Comments
Richard MacCutchan 27-Mar-22 5:50am    
The only way to solve this is to use the debugger to find out whether your path string is actually returning any data. And trying to use such a string (for eight levels) in one call is not a good idea. You should do it step by step so that you can check at each step whether it has found the node you want.
Dave Kreskowiak 27-Mar-22 12:11pm    
It's "scrape", not "scrap".

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900