Skip to content

Instantly share code, notes, and snippets.

@wildbillcat
Created September 6, 2016 13:11
Show Gist options
  • Save wildbillcat/5da66cbafc75ef96650e569f4b644d6d to your computer and use it in GitHub Desktop.
Save wildbillcat/5da66cbafc75ef96650e569f4b644d6d to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Net;
using HtmlAgilityPack;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
string websiteUrl = "";
string xpath = "//*[@id=\"price\"]/text()";
//*[@id="price"]/text()
List<string> content = new List<string>();
using (WebClient client = new WebClient())
{
client.Headers.Add("user-agent", "Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20100101 Firefox/21.0");
string pageContent = client.DownloadString(websiteUrl);
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(pageContent);
foreach (HtmlNode scrape in doc.DocumentNode.SelectNodes(xpath))
{
content.Add(scrape.InnerText);
}
}
string csvLine = string.Join(",", content.ToArray());
Console.WriteLine(csvLine);
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment