-
-
Save rvvvt/40c1e3886ed083903cec307e98bf3aa3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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