/// <summary> /// Gets the ip address. /// </summary> /// <returns></returns> public override string GetIpAddress() { try { Scraper scraper = new Scraper(); PrepareScraper(scraper); ScrapedPage checkip = scraper.Scrape(ScrapeType.GET, m_url); if (checkip != null && checkip.RawStream != null) { if (string.IsNullOrEmpty(m_successRegex)) { string result = checkip.RawStream.Trim(); if (StringUtilities.ExtractFirstNumber(result) > 0) { return result; } } else { return RegexUtilities.Extract(checkip.RawStream, m_successRegex, m_captureIndex); } } } catch (Exception) { } return null; }
/// <summary> /// Prepares the scraper. /// </summary> /// <param name="scraper">The scraper.</param> protected override void PrepareScraper(Scraper scraper) { if (!string.IsNullOrEmpty(m_userName)) { scraper.UseCredentials = true; scraper.SetNetworkCredentials(m_userName, m_password); } }
public void play() { LenientHtmlDocument doc = new LenientHtmlDocument(); foreach (string url in new string[] { "http://www.cnn.com/", "http://www.google.com/", "http://www.bankofamerica.com/", "http://www.citicard.com/" }) { try { Scraper scraper = new Scraper(); ScrapedPage page = scraper.Scrape(ScrapeType.GET, url); doc.LoadXml(page.RawStream); Console.WriteLine(doc.InnerXml); } catch (System.Net.WebException) { } } }
/// <summary> /// Initializes a new instance of the <see cref="ScrapeSession"/> class. /// </summary> /// <param name="scraper">The scraper.</param> public ScrapeSession(Scraper scraper) { ContainingScraper = scraper; }
/// <summary> /// Scrapes the specified type. /// </summary> /// <param name="type">The type.</param> /// <param name="uri">The URI.</param> /// <param name="userName">Name of the user.</param> /// <param name="password">The password.</param> /// <param name="query">The query.</param> /// <returns></returns> public static ScrapedPage SimpleScrape(ScrapeType type, string uri, string userName, string password, NameValueCollection query) { Scraper scraper = new Scraper(); if (!string.IsNullOrEmpty(userName)) { scraper.UseCredentials = true; scraper.SetNetworkCredentials(userName, password); } return scraper.Scrape(type, uri, query); }
/// <summary> /// Prepares the scraper. /// </summary> /// <param name="scraper">The scraper.</param> protected virtual void PrepareScraper(Scraper scraper) { }