开发者

Is it possible to screen scrape and display only one div/ Table

开发者 https://www.devze.com 2023-04-01 08:08 出处:网络
Is it possible to webscrape using HTTPWebRequest or webclient and display only a specfic div or table like the example below?

Is it possible to webscrape using HTTPWebRequest or webclient and display only a specfic div or table like the example below?

This is one div from a page of other divs, just to give you a structure example.

     <div id="DIV5">

            <table cellspacing="0" cellpadding="0"><tbody>

                <tr class="">

                <tr class="last">

            </table>

</div>

I have this simple code which displays the HTML from the page, but I am looking for a way to display only one DIV or One table.

namespace SimpleScreenScrape
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string html = this.GetWebsiteHtml(this.textBox1.Text);
            this.richTextBox1.Text = html;
        }

        private string GetWebsiteHtml(string url)
        {
            WebRequest request = WebRequest.Create(url);
            WebResponse response = request.GetResponse();
            Stream stream = response.GetResponseStream();
            StreamRea开发者_JAVA百科der reader = new StreamReader(stream);
            string result = reader.ReadToEnd();
            stream.Dispose();
            reader.Dispose();
            return result;
        }




    }
}


Generally speaking, once you have the HTML document (stored in your result variable), you can parse it and display only the parts of it that you want.

I suggest you use a dedicated HTML parser such as the HTML Agility Pack - this will allow you to easily extract only the HTML you are interested in.

0

精彩评论

暂无评论...
验证码 换一张
取 消