Hello There, Guest!
View New Posts  |  View Today's Posts
[C#] Add Mulit array to listview?

  • 0 Vote(s) - 0 Average


03-26-2016, 03:34 PM #1
ѕα3єкα
Junior Member
**
Posts: 37 Threads:12 Joined: Dec 2012 Reputation: 0

Add Mulit array to listview?
Can anybody help me with this?
I am trying to add scraped data (title/desc) to listview with htmlagility pack.
Its not working
Code:
using System;
using System.Windows.Forms;
using HtmlAgilityPack;

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

       private void button1_Click(object sender, EventArgs e)
       {
           var website = new HtmlWeb();
           var url = website.Load("https://www.youtube.com/results?search_query=google");
           var titleTags = url.DocumentNode.SelectNodes("//a[contains(@class, 'yt-uix-sessionlink yt-uix-tile-link yt-ui-ellipsis yt-ui-ellipsis-2       spf-link ')]");
           var desTags = url.DocumentNode.SelectNodes("//div[contains(@class, 'yt-lockup-description yt-ui-ellipsis yt-ui-ellipsis-2')]");

           foreach (var titles in titleTags)
           {
               
               
               foreach (var descp in desTags)
               {
                   var titleList = titles.InnerText;
                   var descList = descp.InnerText;
                   string[] arr = new string[1];
                   ListViewItem item;
                   arr[0] = titleList;
                   arr[1] = descList;
                   item = new ListViewItem(arr);
                   listView1.Items.Add(item);
                   
                   
                   


               }
             
           }
           

       }
   }
}
This post was last modified: 03-26-2016, 03:35 PM by ѕα3єкα.

03-27-2016, 11:47 PM #2
AceInfinity
Developer
*******
Administrators
Posts: 9,733 Threads:1,026 Joined: Jun 2011 Reputation: 76

RE: Add Mulit array to listview?
You're querying Google search pages which works a bit differently than other websites because Google does not want people to scrape all of their data for the most part. I haven't tried to query google search results for quite a while now, but you shouldn't need the HtmlAgilityPack anymore either, it's outlived it's usefulness as far as I know -- especially with newer .NET libraries and features/functionality.

Breakpoint through and check the contents of your variables.

What exactly isn't working? :S
This post was last modified: 03-27-2016, 11:48 PM by AceInfinity.


Microsoft MVP .NET Programming - (2012 - Present)
®Crestron DMC-T Certified Automation Programmer

Development Site: aceinfinity.net

 ▲
 ▲ ▲




Forum Jump:


Possibly Related Threads...
Thread Author Replies Views Last Post
   [Question] Optimize listview for database queries? Sam Baker 6 2,245 10-17-2015, 04:51 PM
Last Post: AceInfinity
Brick Listview Loading textfile progress Onlykl 2 1,869 11-23-2014, 02:43 AM
Last Post: sh@rp
   Switching Array Values - LINQ AceInfinity 5 3,212 12-14-2013, 05:31 PM
Last Post: AceInfinity
  Listview freezes ? 1912Dummy 14 6,252 09-20-2013, 09:20 PM
Last Post: AceInfinity
  [Help] Problem with Looping using data from ListView iNFIDEL_ 3 2,279 08-24-2013, 11:51 AM
Last Post: AceInfinity


Users browsing this thread: 1 Guest(s)