private async Task LoadContent(DataItem _item)
        {
            string contentStr = string.Empty;
            try
            {
                contentStr = await Define.DownloadStringAsync(_item.Link);
            }
            catch (Exception ex)
            {

                //throw;
            }

            if (contentStr != string.Empty)
            {
                HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
                htmlDoc.LoadHtml(contentStr);

                HtmlAgilityPack.HtmlNode htmlNode = htmlDoc.GetElementbyId("ContentContainer");
                while (htmlNode.Descendants("script").Count() > 0)
                {
                    htmlNode.Descendants("script").ElementAt(0).Remove();
                }
                while (htmlNode.Descendants("meta").Count() > 0)
                {
                    htmlNode.Descendants("meta").ElementAt(0).Remove();
                }

                //contentStr = "<p><i>This blog post was authored by Andrew Byrne (<a href=\"http://twitter.com/AndrewJByrne\" target=\"_blank\">@AndrewJByrne</a>), a Senior Content Developer on the Windows Phone Developer Content team.</i> <p><i></i> <p><i>- Adam</i></p> <hr>  <p> <table cellspacing=\"1\" cellpadding=\"2\" width=\"722\" border=\"0\"> <tbody> <tr> <td valign=\"top\" width=\"397\"> <p>The Windows Phone Developer Content team is continually adding new code samples that you can download from MSDN. In this post, we introduce you to the 10 latest samples that we’ve posted on MSDN. Each sample includes a readme file that walks you through building and running the sample, and includes links to relevant, related documentation. We hope these samples help you with your app development and we look forward to providing more samples as we move forward. You can check out all of our <a href=\"http://code.msdn.microsoft.com/wpapps/site/search?f%5B0%5D.Type=Contributors&amp;f%5B0%5D.Value=Windows%20Phone%20SDK%20Team&amp;f%5B0%5D.Text=Windows%20Phone%20SDK&amp;sortBy=Date\" target=\"_blank\">samples on MSDN</a>.</p></td> <td valign=\"top\" width=\"320\"> <p><a href=\"http://blogs.windows.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-53-84-metablogapi/clip_5F00_image002_5F00_1765A66A.png\"><img title=\"clip_image002\" style=\"border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto\" border=\"0\" alt=\"clip_image002\" src=\"http://blogs.windows.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-53-84-metablogapi/clip_5F00_image002_5F00_thumb_5F00_7B083E7C.png\" width=\"121\" height=\"213\"></a></p></td></tr></tbody></table></p> <h3><a href=\"http://go.microsoft.com/fwlink/?LinkId=306704\" target=\"_blank\">Stored Contacts Sample</a></h3> <p>This sample illustrates how to use the <a href=\"http://msdn.microsoft.com/en-us/library/windowsphone/develop/windows.phone.personalinformation.contactstore(v=vs.105).aspx\" target=\"_blank\">ContactStore</a> class and related APIs to create a contact store for your app. This feature is useful if your app uses an existing cloud-based contact store. You can use the APIs you to create contacts on the phone that represent the contacts in your remote store. You can display and modify the contacts in the People Hub on your phone, just like contacts that are added through the built-in experience. You can use the APIs to update and delete contacts you have created on the phone and also to query for any changes the user has made to the contacts locally so you can sync those changes to your remote store. <h3><a href=\"http://go.microsoft.com/fwlink/?LinkId=306701\" target=\"_blank\">Basic Storage Recipes</a></h3> <p>This is a “Windows Runtime Storage 101” sample for Windows Phone developers moving from isolated storage and <b>System.IO</b> to <a href=\"http://msdn.microsoft.com/en-us/library/windowsphone/develop/windows.storage.aspx\" target=\"_blank\">Windows.Storage</a> and <a href=\"http://msdn.microsoft.com/en-us/library/windowsphone/develop/windows.storage.streams.aspx\" target=\"_blank\">Windows.Storage.Streams</a>. The sample demonstrates how to write to and read files, in addition to how to enumerate directory trees. It also demonstrates how to pass data from one page to the next, and how to persist application state when the app is deactivated. <h3><a href=\"http://go.microsoft.com/fwlink/?LinkId=301509\" target=\"_blank\">Trial Experience Sample</a></h3> <p>This sample shows you how to design your app to detect its license state when the app launches, and how to detect changes to the license state while running. It comes with a helper class that you can use in your app to wrap <a href=\"http://msdn.microsoft.com/en-us/library/windowsphone/develop/windows.applicationmodel.store.licenseinformation.aspx\" target=\"_blank\">LicenseInformation</a> functionality. <h3><a href=\"http://go.microsoft.com/fwlink/?LinkId=302059\" target=\"_blank\">Windows Runtime Component Sample</a></h3> <p>This sample demonstrates the basics of creating a Windows Phone Runtime component in C++ and consuming it in a XAML app. The sample demonstrates three scenarios: the first scenario illustrates how to call synchronous and asynchronous methods to perform a computation. The second scenario uses the same computation component to demonstrate progress reporting and cancellation of long-running tasks. Finally, the third scenario shows how to use a component to wrap logic that uses <a href=\"http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj206944(v=vs.105).aspx\" target=\"_blank\">XAudio2 APIs</a> to play a sound. <h3><a href=\"http://go.microsoft.com/fwlink/?LinkId=306097\" target=\"_blank\">Company Hub Sample</a></h3> <p>This sample demonstrates the construction of an app that is capable of deploying line-of-business (LOB) apps to employees of a corporation. The sample uses an example XML file to define the company XAPs that are available to employees for secure download, and shows you how to dynamically access that file at run time. Then it shows you how to install company apps, enumerate the apps, and then launch the installed company apps. This app is just an example framework and requires additional work beyond the sample to be functional. <h3><a href=\"http://go.microsoft.com/fwlink/?LinkId=306702\" target=\"_blank\">Image Recipes</a></h3> <p>This sample illustrates how to use images in your app efficiently, while giving your users a great experience. It tackles downsampling images, implementing pinch and zoom, and downloading images with a progress display and an option to cancel the download. We’ve taken a recipe approach: each recipe is delivered in a self-contained page in the app so you can focus your attention on the particular part of the sample you are most interested in.  <h3><a href=\"http://go.microsoft.com/fwlink/?LinkId=306026\" target=\"_blank\">Azure Voice Notes</a></h3> <p>This sample uses Windows Phone speech recognition APIs and Windows Azure Mobile Services to record voice notes as text and store the notes in the cloud. It shows how Mobile Services can be used to authenticate a user with their Microsoft Account. It also demonstrates how to use Mobile Services to store, retrieve, and delete data from an Azure database table. The app generates text from speech using the Windows Phone speech recognition APIs and the phone’s predefined dictation grammar. <h3><a href=\"http://go.microsoft.com/fwlink/?LinkId=299241\" target=\"_blank\">Kid's Corner Sample</a></h3> <p>This sample illustrates how to use the <a href=\"http://msdn.microsoft.com/en-us/library/windowsphone/develop/windows.phone.applicationmodel.applicationprofile.modes(v=vs.105).aspx\" target=\"_blank\">ApplicationProfile.Modes</a> property to recognize Kid’s Corner mode. When the app runs, it checks the <a href=\"http://msdn.microsoft.com/en-us/library/windowsphone/develop/windows.phone.applicationmodel.applicationprofile.modes(v=vs.105).aspx\" target=\"_blank\">ApplicationProfile.Modes</a> property. If the value is <b>ApplicationProfileModes.Alternate</b>, you’ll know that the app is running in Kid’s Corner mode. Depending on the content of your app, you may want to change its appearance or features when it runs in Kid’s Corner mode. Some features that you should consider disabling when running in Kid’s Corner mode include in-app purchases, launching the web browser, and the ad control. <h3><a href=\"http://go.microsoft.com/fwlink/?LinkId=267468\" target=\"_blank\">URI Association Sample</a></h3> <p>Use this sample to learn how to automatically launch your app via URI association. This sample includes three apps: a URI launcher, and two apps that handle the URI schemes that are built in to the launcher app. You can launch an app that is included with the sample or edit the URI and launch a different app. There is also a button for launching a URI on another phone using Near Field Communication (NFC).  <h3><a href=\"http://go.microsoft.com/fwlink/?LinkId=275007\" target=\"_blank\">Speech for Windows Phone: Speech recognition using a custom grammar</a></h3> <p>A grammar defines the words and phrases that an app will recognize in speech input. This sample shows you how to go beyond the basics to create a powerful grammar (based on the grammar schema) with which your app can recognize commands and phrases constructed in different ways. <p>&nbsp; <p>This post is just a glimpse of the latest Windows Phone samples we’ve added to the MSDN code gallery. From launching apps with URI associations, to dictating notes and storing them in the cloud, we hope that there’s something for everyone. We’ll be sure to keep you posted as new samples are added to the collection, so stay tuned. In the meantime, grab the samples, experiment with them, and use the code to light up your apps. You can download all Windows Phone samples at <a href=\"http://code.msdn.microsoft.com/wpapps\" target=\"_blank\">http://code.msdn.microsoft.com/wpapps</a>. <div style=\"clear:both;\"></div><img src=\"http://blogs.windows.com/aggbug.aspx?PostID=588575&AppID=5384&AppType=Weblog&ContentType=0\" width=\"1\" height=\"1\">";
                Items[Items.IndexOf(_item)].Content = htmlNode.InnerHtml.Replace("\r", "").Replace("\n", "");
            }
        }
Exemple #2
0
        public Salestate[] GetSalestates()
        {
            var http_salestate_list_url = "https://creator.toranoana.jp/portal/salestate_list.cgi";
            var salestate_page_key = "salestate_page";

            WebClientEx webClient = new WebClientEx();
            webClient.CookieContainer = Cookie;

            // 売上ページ一覧を取得
            var buffer = webClient.DownloadData(http_salestate_list_url);
            var htmlString = ConvertHtmlBufferToString(buffer);

            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            doc.LoadHtml(htmlString);

            // 売上ページのみへのリンク取得
            var saleStateLinks = doc.DocumentNode.SelectNodes("//a").Where(_=>_.GetAttributeValue("href", "").Contains(salestate_page_key));

            var baseURI = new Uri(http_salestate_list_url);
            List<Salestate> salestates = new List<Salestate>();
            foreach (var link in saleStateLinks)
            {
                // 売上ページを走査
                var uri = new Uri( baseURI, link.GetAttributeValue("href", ""));
                salestates.Add(GetSalestate(webClient, uri.ToString()));
            }

            return salestates.ToArray();
        }
 /// <summary>
 /// Converts onlyconnect.IHTMLDocument2 class to HtmlAgilityPack.HtmlDocument
 /// </summary>
 /// <param name="doc">IHTMLDocument2 document</param>
 /// <returns>Converted HtmlDocument</returns>
 public static HtmlAgilityPack.HtmlDocument mshtmlDocToAgilityPackDoc(onlyconnect.IHTMLDocument2 doc)
 {
     HtmlAgilityPack.HtmlDocument outDoc = new HtmlAgilityPack.HtmlDocument();
     string html = doc.GetBody().innerHTML;
     outDoc.LoadHtml(html);
     return outDoc;
 }
Exemple #4
0
 public async Task<HtmlAgilityPack.HtmlDocument> RetrieveHtmlGet(string url)
 {
     var html = await RetrieveHtmlStrGet(url);
     var htmlDoc = new HtmlAgilityPack.HtmlDocument();
     htmlDoc.LoadHtml(html);
     return htmlDoc;
 }
        /// <summary>
        /// Get all transfers data as list of strings.
        /// </summary>
        /// <param name="htmlDocument">HTML document string representation.</param>
        /// <returns>String list of data.</returns>
        public List<String> GetTransfersData(string htmlDocument)
        {
            // Data container.
            List<string> dataToSave = new List<string>();

            // Load downloaded website.
            HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
            htmlDoc.LoadHtml(htmlDocument);

            // Find proper HTML element with transfers 'table'.
            HtmlAgilityPack.HtmlNode div = htmlDoc.DocumentNode.SelectSingleNode("//div[@class='panes']");

            // Get all players with data, each data element as separate list element.
            if (div != null)
            {
                dataToSave = div.Descendants("li")
                               .Select(a => a.InnerText)
                               .ToList();
            }
            else
            {
                throw new Exception("Could not find div with transfers!");
            }

            return dataToSave;
        }
        void getGalleryResponse(IAsyncResult result)
        {
            HttpWebRequest request = result.AsyncState as HttpWebRequest;
            if (request != null)
            {
                try
                {
                    WebResponse response = request.EndGetResponse(result);
                    Stream outStream = response.GetResponseStream();
                    StreamReader reader = new StreamReader(outStream);
                    string xmlResult = reader.ReadToEnd();
                    
                    HtmlAgilityPack.HtmlDocument xdoc = new HtmlAgilityPack.HtmlDocument();
                    xdoc.LoadHtml(xmlResult);

                    HtmlAgilityPack.HtmlNodeCollection posts = xdoc.DocumentNode.SelectNodes("tumblr/posts/post[@type='photo']");
                    foreach (HtmlAgilityPack.HtmlNode post in posts)
                    {
                        string targetUri = post.SelectSingleNode("photo-url[@max-width='400']").InnerHtml;
                        imageUriList.Add(targetUri);
                    }
                    populatePivot();
                }
                catch (WebException e)
                {
                   return;
                }
            }
        }
        public override int DiscoverDynamicCategories()
        {
            int dynamicCategoriesCount = 0;
            String baseWebData = GetWebData(PrimaUtil.categoriesUrl, forceUTF8: true);

            HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
            document.LoadHtml(baseWebData);

            HtmlAgilityPack.HtmlNodeCollection categories = document.DocumentNode.SelectNodes(".//div[@class='programs-menu-genres']/*/a");

            foreach (var category in categories)
            {
                this.Settings.Categories.Add(
                    new RssLink()
                    {
                        Name = category.InnerText,
                        HasSubCategories = true,
                        Url = Utils.FormatAbsoluteUrl(category.Attributes["href"].Value, PrimaUtil.categoriesUrl)
                    });

                dynamicCategoriesCount++;
            }

            this.Settings.DynamicCategoriesDiscovered = true;
            return dynamicCategoriesCount;
        }
 private static void GetChannelList(string webHtml)
 {
     var doc = new HtmlAgilityPack.HtmlDocument();
     doc.LoadHtml(webHtml);
     var aList = doc.DocumentNode.Descendants("a")
         .Where(u =>
         (!string.IsNullOrEmpty(u.GetAttributeValue("href", "")) &&
         u.GetAttributeValue("class", "").Equals("btn btn-block btn-primary"))
         || (string.IsNullOrEmpty(u.GetAttributeValue("href", "")) && string.IsNullOrEmpty(u.GetAttributeValue("class", "")))
         ).ToArray();
     var length = aList.Count(u => string.IsNullOrEmpty(u.GetAttributeValue("href", "")));
     var clModels = new ChannelListJsonModel[length];
     var i = -1;
     foreach (var a in aList)
     {
         if (string.IsNullOrEmpty(a.GetAttributeValue("href", "")))
         {
             clModels[++i] = new ChannelListJsonModel();
             clModels[i].ChannelList = new List<ChannelModel>();
             clModels[i].ChannelBelong = a.InnerText;
             continue;
         }
         if (i < 0) continue;
         clModels[i].ChannelList.Add(
             new ChannelModel
             {
                 ChannelUrl = a.GetAttributeValue("href", ""),
                 ChannelName = a.InnerText
             });
     }
     Channels = new ObservableCollection<ChannelListJsonModel>(clModels);
 }
        public static void FillDbFromSite()
        {
            // Add Currency
            banks.Сurrency.Add(new Сurrency() { Name = "USD" });
            banks.Сurrency.Add(new Сurrency() { Name = "EUR" });
            banks.Сurrency.Add(new Сurrency() { Name = "RUB" });
            banks.Сurrency.Add(new Сurrency() { Name = "EUR -> USD" });

            //Add Banks
            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            WebClient wc = new WebClient();
            wc.Encoding = Encoding.UTF8;
            doc.LoadHtml(wc.DownloadString("http://myfin.by/currency/minsk"));

            foreach (HtmlAgilityPack.HtmlNode tablet in doc.DocumentNode.SelectNodes("//*[@id='workarea']/div[3]/div[3]/div/table/tbody/tr[1]"))
            {
                foreach (HtmlAgilityPack.HtmlNode row in tablet.SelectNodes("td[1]"))
                {
                    banks.Bank.Add(new Bank() { Name = row.InnerText });
                }
            }

            
            //banks.Department.Add(new Department() { });

            //banks.DeprtmentsСurrencies.Add(new Department());


            banks.SaveChanges();
        }
Exemple #10
0
        public IPttCaptcha CaptchaImage(IPttRequest request, string htmlSource)
        {
            var htmlDoc = new HtmlAgilityPack.HtmlDocument();
            htmlDoc.LoadHtml(htmlSource);
            var iframe = htmlDoc.DocumentNode.SelectSingleNode("//iframe");
            if (iframe == null)
            {
                return null;
            }
            var iframeSrc = iframe.Attributes["src"].Value;

            var newRequest = new PttRequest(iframeSrc) {WrappedRequest = {ContentType = "text/html", Method = "GET"}};
            IPttResponse response = new PttResponse();
            var captchaFormHtml = response.GetResponse(newRequest);

            htmlDoc = new HtmlAgilityPack.HtmlDocument();
            htmlDoc.LoadHtml(captchaFormHtml);
            var captchaImg = htmlDoc.DocumentNode.SelectSingleNode("//img");
            if (captchaImg == null)
            {
                return null;
            }
            var captchaSrc = string.Format("http://{0}/recaptcha/api/{1}", googleHost, captchaImg.Attributes["src"].Value);

            return new PttCaptcha() { Url = captchaSrc, RequestUsed = newRequest, FormUrl = iframeSrc};
        }
		private static List<Exhibitor> GetExtendedData(List<Exhibitor> exhibitors)
		{
			foreach(var exhibitor in exhibitors)
			{
				string url = baseUrl + exhibitor.DetailUrl;
				string html = WebHelper.HttpGet(url);

				HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
				doc.LoadHtml(html);

				exhibitor.Overview = HtmlDocHelper.GetInnerText(doc, "//*[@id=\"page_content_ctl00_ctl00_divDescription\"]");
				exhibitor.Tags = HtmlDocHelper.GetInnerText(doc, "//*[@id=\"page_content_ctl00_ctl00_ulDetailTags\"]");
				exhibitor.Email = HtmlDocHelper.GetInnerText(doc, "//*[@id=\"page_content_ctl00_ctl00_hlEmail\"]");
				exhibitor.Phone = HtmlDocHelper.GetInnerText(doc, "//*[@id=\"page_content_ctl00_ctl00_divTel\"]").Replace("Tel:", "").Trim();
				exhibitor.Fax = HtmlDocHelper.GetInnerText(doc, "//*[@id=\"page_content_ctl00_ctl00_divFax\"]").Replace("Fax:", "").Trim();
				exhibitor.ImageUrl = HtmlDocHelper.GetAttribute(doc.DocumentNode, "//*[@id=\"page_content_ctl00_ctl00_imgExhibitorDetail\"]", "src");
				
				var nodes = doc.DocumentNode.SelectNodes("//ul[@id=\"page_content_ctl00_ctl00_ulDetailAddress\"]/li");
				if(nodes != null)
				{
					List<string> addressParts = new List<string>();
					foreach(var node in nodes)
					{
						addressParts.Add(node.InnerText);
					}
					exhibitor.Address = string.Join(", ", addressParts);
				}
			}
			return exhibitors;
		}
        private static HtmlAgilityPack.HtmlDocument LoadHtml()
        {
            var doc = new HtmlAgilityPack.HtmlDocument();
            doc.LoadHtml(Resource.GetString("Test1.html"));

            return doc;
        }
Exemple #13
0
        public IPttRequest RequestWithCaptchaValue(IPttRequest request, IPttCaptcha pttCaptcha)
        {
            var htmlDoc = new HtmlAgilityPack.HtmlDocument();
            htmlDoc.LoadHtml(request.Response);

            var challengeField = htmlDoc.DocumentNode.SelectSingleNode("//input[@id='recaptcha_challenge_field']");
            if (challengeField == null)
            {
                return null;
            }
            var challengeFieldValue = challengeField.Attributes["value"].Value;

            var pttRequestFactory = new PttRequestFactory(request);
            var newReq = pttRequestFactory.Deserialize(string.Format("<Request><Url>{0}</Url><Method>POST</Method></Request>", request.Url));

            newReq.PostValue = string.Format("recaptcha_challenge_field={0}&recaptcha_response_field={1}&submit=I%27m+a+human", challengeFieldValue, pttCaptcha.Value ?? "");
            newReq.WrappedRequest.ContentType = "application/x-www-form-urlencoded";

            var pttResponse = new PttResponse();
            //bu gelen htmlsource dan textarea degerini oku
            htmlDoc = new HtmlAgilityPack.HtmlDocument();
            htmlDoc.LoadHtml(pttResponse.GetResponse(newReq));
            var valueToPasteNode = htmlDoc.DocumentNode.SelectSingleNode("//textarea");
            if (valueToPasteNode == null)
            {
                return null;
            }

            return null;
        }
Exemple #14
0
        static void Main(string[] args)
        {
            string html =
                @"<div class=""article-content"">
                   <p>text I want text I want text I want text I want <strong> TEXT I WANT TOO </strong></p>
                   <p>text I want text I want text I want text I want <strong> TEXT I WANT TOO </strong></p>
                </div>";

            using (WebClient client = new WebClient())
            {
                client.Encoding = System.Text.Encoding.Unicode;
                var doc = new HtmlAgilityPack.HtmlDocument();
                doc.LoadHtml(html);

                var nodes = doc.DocumentNode.SelectNodes("//div[@class='article-content']/p");

                nodes.ToList().ForEach(n =>
                {
                    Console.WriteLine(n.InnerText);
                });

                Console.ReadLine();

            }
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            // 例えば ConverterParameter=true とすると、parameter に string "true" が入ります。
            if (value == null)
                return "";

            // HtmlAgilityPack を使用してタグ付きの string からタグを除去します。
            var hap = new HtmlAgilityPack.HtmlDocument();
            hap.LoadHtml(value.ToString());
            var doc = hap.DocumentNode.InnerText;
            doc = doc.Replace(@"&nbsp;", " ").Replace(@"&lt;", "<").Replace(@"&gt;", ">").Replace(@"&amp;", "&").Replace(@"&quot;", "\"");

            var multiCRRegex = new Regex(@"\n\n\n+");
            doc = multiCRRegex.Replace(doc, "\n\n");

            // parameter には数字が入りますので、数値があればその文字数でカットした string を返します。
            int strLength;
            if (int.TryParse(parameter as string, out strLength)) {
                if (doc.Length > strLength)
                {
                    return doc.Substring(0, strLength) + "…";
                }
                return doc;
            }
            else
            {
                return doc;
            }
        }
		internal static string ExtractFilmTitleUsingXPath(string html)
		{


			//TODO: Currently the film's Original Title is used as the default Title. If no Original Title is available, we should get the film's default title.

			var doc = new HtmlDocument();

			doc.LoadHtml(html);

			HtmlAgilityPack.HtmlNode htmlNode
				= doc.DocumentNode.SelectSingleNode
					(@"//span[@class='title-extra']");

		    string originalTitle = htmlNode.InnerText;


			////TODO: The xml data should be loaded and received from memory instead of a file.

			

			originalTitle = RegExDataMiners.MatchRegexExpressionReturnFirstMatchFirstGroup
				(originalTitle, "\"(?<Title>.*?)\"");


			//MessageBox.Show(originalTitle);

			return (originalTitle);


		}
Exemple #17
0
        private AmazonProduct GetContent(String ASin)
        {
            var content = "";

            var client = new WebClient();

            var headers = new WebHeaderCollection();

            headers.Add(HttpRequestHeader.Accept, "text/html, application/xhtml+xml, */*");
            //headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
            headers.Add(HttpRequestHeader.AcceptLanguage, "en-GB");
            headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko");

            client.Headers = headers;

            var rawhtml = client.DownloadString("http://www.amazon.co.uk/dp/"+ ASin);

            HtmlAgilityPack.HtmlDocument Html = new HtmlAgilityPack.HtmlDocument();

            Html.LoadHtml(rawhtml);

            var title = GetTitle(Html);

            var description = GetDescription(Html);

            AmazonProduct prod = new AmazonProduct() { Description = description, Title = title };

            return prod;
        }
        internal static string[] MatchXpathExpressionReturnAllMatches
            (string html, string xPathExpression)
        {


            var doc = new HtmlDocument();

            doc.LoadHtml(html);

            HtmlAgilityPack.HtmlNodeCollection htmlNodesCollection
                = doc.DocumentNode.SelectNodes
                    (xPathExpression);

            var matches = new List<string>();

            foreach (var htmlNode in htmlNodesCollection)
            {
                matches.Add(htmlNode.InnerText);

            }





            return matches.ToArray();

        }
Exemple #19
0
        /// <summary>
        /// 返回 报关单号, 报关单pre_entry_id
        /// </summary>
        /// <param name="htmlInfo"></param>
        /// <returns></returns>
        internal static Dictionary<string, string> Parse查询所有报关单号2(string htmlInfo)
        {
            Dictionary<string, string> dic = null;
            HtmlAgilityPack.HtmlDocument _html = new HtmlAgilityPack.HtmlDocument();
            _html.LoadHtml(htmlInfo);

            HtmlAgilityPack.HtmlNode node_table = _html.DocumentNode.SelectSingleNode("/html[1]/body[1]/table[2]");
            if (node_table != null)
            {
                dic = new Dictionary<string, string>();
                int trCount = new Regex("<tr>").Matches(node_table.InnerHtml).Count;
                for (int i = 2; i <= trCount; i++)
                {
                    //报关单号
                    HtmlAgilityPack.HtmlNode node_td1 = _html.DocumentNode.SelectSingleNode(string.Format("/html[1]/body[1]/table[2]/tr[{0}]/td[2]/div[1]/a[1]", i));
                    //地址
                    HtmlAgilityPack.HtmlNode node_td2 = _html.DocumentNode.SelectSingleNode(string.Format("/html[1]/body[1]/table[2]/tr[{0}]/td[7]/div[1]/a[1]", i));
                    string url = null;
                    if (node_td2 != null)
                    {
                        //去掉“../”,拼成报关单快照url
                        //url = "http://www.nbedi.com/h2000eport/pre_bgd/" + node_td2.InnerText.Substring(3);

                        //报关单pre_entry_id
                        string att = node_td2.Attributes["href"].Value;
                        url = att.Substring(att.LastIndexOf("=") + 1);
                    }
                    dic.Add(node_td1.InnerText, url);
                }
            }
            return dic;
        }
Exemple #20
0
        //private static Regex m_regexBgdh = new Regex(@"type=""checkbox"" value=""(.*?)"">", RegexOptions.Singleline);
        internal static List<string> Parse查询所有报关单号(string htmlInfo)
        {
            List<string> bgdhList = new List<string>();

            HtmlAgilityPack.HtmlDocument _html = new HtmlAgilityPack.HtmlDocument();
            _html.LoadHtml(htmlInfo);

            HtmlAgilityPack.HtmlNode node_table = _html.DocumentNode.SelectSingleNode("/html[1]/body[1]/table[2]");

            // 判断table的<tr>确定每页的记录条数
            // 列头<tr class="table1">被忽略,当前页记录条数 + 一个分页<tr>
            int trCount = new Regex("<tr>").Matches(node_table.InnerHtml).Count;

            for (int i = 2; i <= trCount; i++)  // 去掉列头<tr>和分页<tr>
            {
                HtmlAgilityPack.HtmlNode node_bgdh = _html.DocumentNode.SelectSingleNode(
                    string.Format("/html[1]/body[1]/table[2]/tr[{0}]/td[1]/div[1]/input[1]/@value[1]", i));
                bgdhList.Add(Feng.Net.WebProxy.RemoveSpaces(node_bgdh.Attributes["value"].Value));
            }

            //foreach (Match match in m_regexBgdh.Matches(htmlInfo))
            //{
            //    bgdhList.Add(match.Groups[1].Value);
            //}
            return bgdhList;
        }
Exemple #21
0
        public XmlNodeList GetNCTSongs(string html)
        {
            XmlDocument songDoc = new XmlDocument();
            try
            {
                HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
                htmlDoc.LoadHtml(html);
                //http://www.nhaccuatui.com/flash/xml?html5=true&key2=469177aa57117104d2e3d1ea0da2b3bc
                string pattern = @"http:\/\/www\.nhaccuatui.com\/flash\/xml\?(html5=true&)?key(2|1)=.*";
                Match match = Regex.Match(html, pattern, RegexOptions.IgnoreCase | RegexOptions.Multiline);
                string xmlURL = "";
                if (match.Success)
                {
                    xmlURL = match.Value;
                }
                int objIndex = xmlURL.IndexOf("\"");
                xmlURL = xmlURL.Substring(0, objIndex);
                AlbumName = htmlDoc.DocumentNode.SelectSingleNode("//h1[@itemprop='name']").InnerText;
                objHTML.URL = xmlURL;

                string songXML = objHTML.GetHTMLString();

                songDoc.LoadXml(songXML);
            }
            catch (Exception ex)
            {

                throw ex;
            }
            return songDoc.SelectNodes("//track");
        }
        public override List<Show> Grab(string xmlParameters, ILogger logger)
        {
            var shows = new List<Show>();

            var doc = XDocument.Parse(xmlParameters);
            var sdElement = doc.Descendants("StartDate").FirstOrDefault();
            var startDateDiff = sdElement != null && sdElement.Value != null ? Convert.ToInt32(sdElement.Value) : -1;
            var edElement = doc.Descendants("EndDate").FirstOrDefault();
            var endDateDays = edElement != null && edElement.Value != null ? Convert.ToInt32(edElement.Value) : 3;
            for (int i = startDateDiff; i <= endDateDays; i++)
            {
                var date = DateTime.Now.Date.AddDays(i);

                var wr = WebRequest.Create(string.Format(URL, date.ToString(DateFormat)));
                logger.WriteEntry(string.Format("Grabbing bein sports date {0} ...", date.ToString(DateFormat)), LogType.Info);
                var res = (HttpWebResponse)wr.GetResponse();

                var data = XDocument.Load(res.GetResponseStream());
                var html = new HtmlAgilityPack.HtmlDocument();
                html.LoadHtml(data.Descendants("body").First().Value);

                var sections = html.DocumentNode.Descendants("section").ToList();
                int divCounter = 0;
                foreach (var section in sections)
                {
                    if (sections.Count > 0)
                    {
                        foreach (var li in sections[divCounter].Descendants("li"))
                        {
                            var time = li.Descendants("time").FirstOrDefault();
                            if (time == null)
                                continue;
                            var show = new Show();
                            var a = li.Descendants("a").FirstOrDefault();
                            if (a == null)
                                continue;
                            show.Channel = "ch-" + a.Attributes["href"].Value.Split('/')[2];
                            show.StartTime = Convert.ToDateTime(time.Attributes["datetime"].Value);
                            show.StartTime = DateTime.SpecifyKind(show.StartTime, DateTimeKind.Utc);
                            var dvText = li.Descendants("div").First();
                            show.Title = dvText.ChildNodes[0].InnerText.Trim();
                            var spans = dvText.Descendants("span").ToList();
                            if (spans.Count > 0)
                                show.Description = spans[0].InnerText.Trim();
                            shows.Add(show);
                        }
                    }
                    divCounter++;
                }
            }
            var lst = new List<Show>();
            foreach (var chan in shows.Select(x => x.Channel).Distinct())
            {
                var channelShows = shows.Where(x => x.Channel == chan).OrderBy(x => x.StartTime).ToList();
                FixShowsEndTimeByStartTime(channelShows);
                lst.AddRange(channelShows);
            }
            return lst;
        }
Exemple #23
0
        public static MatchCollection findImage(string htmlSource)
        {
            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            doc.LoadHtml(htmlSource);
            HtmlAgilityPack.HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes("/img");

            return null;
        }
        public IEnumerable<RSSFeed> FindFeed(string searchFor)
        {
            var rssFeeds = new List<RSSFeed>();

            // get the webpage
            var html = RESTHelper.Helper.GetWebPage(new Uri(_searchUrl));

            // get the select list. agility pack isn't finding it so parse the old school way
            html = html.Substring(html.IndexOf("<select", StringComparison.CurrentCultureIgnoreCase),
                html.IndexOf("</select>", StringComparison.CurrentCultureIgnoreCase) -
                html.IndexOf("<select", StringComparison.CurrentCultureIgnoreCase) + 9);

            // load select with agility pack
            var htmlDoc = new HtmlAgilityPack.HtmlDocument();
            htmlDoc.LoadHtml(html);

            var matches =
                htmlDoc.DocumentNode.ChildNodes[0].ChildNodes.Where(
                    child =>
                        child.NextSibling?.InnerText.IndexOf(searchFor, StringComparison.CurrentCultureIgnoreCase) != -1);

            //get feed url
            foreach (var match in matches)
            {
                var feedId = match.Attributes["value"]?.Value;

                if (feedId == null) continue;

                var xml =
                    RESTHelper.Helper.GetWebPage(new Uri(string.Format(_feedUrl, match.Attributes["value"]?.Value)));
                var xDocument = XDocument.Parse(xml);

                var rssFeed = (from feed in xDocument.Descendants("channel")
                    select new RSSFeed()
                    {
                        FeedUrl = string.Format(_feedUrl, match.Attributes["value"]?.Value),
                        Title = feed.Element("title")?.Value.Replace("showRSS: feed for ", string.Empty),
                        Link = feed.Element("link")?.Value,
                        Description = feed.Element("description")?.Value.Replace("showRSS feed ", string.Empty),
                    }).First();

                rssFeed.Items = from feed in xDocument.Descendants("item")
                    select new RSSFeedItem()
                    {
                        Title = feed.Element("title")?.Value,
                        Link = feed.Element("link")?.Value,
                        Description = feed.Element("description")?.Value,
                        Author = feed.Element("author")?.Value,
                        Category = feed.Element("category")?.Value,
                        Enclosure = feed.Element("enclosure")?.Attribute("url")?.Value,
                        PubDate = feed.Element("pubDate")?.Value
                    };

                rssFeeds.Add(rssFeed);
            }

            return rssFeeds;
        }
Exemple #25
0
        public static void FetchRates(int bankId, string bankName)
        {
            var bankExchange = new BankExchange();

            switch(bankName){
                case "bankasya":
                    {
                        var ds = new DataSet("fxPrices");
                        ds.ReadXml("http://www.bankasya.com.tr/xml/kur_list.xml");

                        bankExchange.USDBuying = Int32.Parse(ds.Tables[1].Rows[0]["Kur"].ToString().Replace(".", ""));
                        bankExchange.USDSelling = Int32.Parse(ds.Tables[1].Rows[1]["Kur"].ToString().Replace(".", ""));
                        bankExchange.EURBuying = Int32.Parse(ds.Tables[1].Rows[2]["Kur"].ToString().Replace(".", ""));
                        bankExchange.EURSelling = Int32.Parse(ds.Tables[1].Rows[3]["Kur"].ToString().Replace(".", ""));

                        Console.WriteLine("BANK ASYA:");
                        Console.WriteLine(bankExchange.ToJSON());
                        Console.WriteLine();
                        break;
                    }
                default:
                    {
                        var doc = new HtmlAgilityPack.HtmlDocument();
                        var res = ("http://kur.doviz.com/" + bankName).DownloadPage();
                        doc.LoadHtml(res);

                        foreach (var li in doc.DocumentNode.SelectNodes("//div[@class='doviz-column btgreen']/ul/li"))
                        {
                            try
                            {
                                var kurClass = li.ChildNodes[1].FirstChild.FirstChild.Attributes["class"];
                                if (!kurClass.Value.StartsWith("flag "))
                                    continue;

                                var kur = kurClass.Value.Split('-')[1];

                                if (kur == "USD")
                                {
                                    bankExchange.USDBuying = (int)(decimal.Parse(li.ChildNodes[5].InnerText) * 100000);
                                    bankExchange.USDSelling = (int)(decimal.Parse(li.ChildNodes[7].InnerText) * 100000);
                                }
                                if (kur == "EUR")
                                {
                                    bankExchange.EURBuying = (int)(decimal.Parse(li.ChildNodes[5].InnerText) * 100000);
                                    bankExchange.EURSelling = (int)(decimal.Parse(li.ChildNodes[7].InnerText) * 100000);
                                }
                            }
                            catch { continue; }
                        }

                        Console.WriteLine(bankName + ":");
                        Console.WriteLine(bankExchange.ToJSON());
                        Console.WriteLine();
                        break;
                    }
            }
        }
        public static string StripTags(string markup)
        {
            var doc = new HtmlAgilityPack.HtmlDocument();
               doc.LoadHtml(markup);

               var output = doc.DocumentNode.ChildNodes.Aggregate(string.Empty, (current, node) => current + node.InnerText);

               return output.Replace("&nbsp;"," ").Replace("\n"," ").Trim();
        }
Exemple #27
0
        private static void RunParallel(int count, string url)
        {
            var locker = new object();
            var proxy = new SocksWebProxy(new ProxyConfig(
                //This is an internal http->socks proxy that runs in process
                IPAddress.Parse("127.0.0.1"),
                //This is the port your in process http->socks proxy will run on
                12345,
                //This could be an address to a local socks proxy (ex: Tor / Tor Browser, If Tor is running it will be on 127.0.0.1)
                IPAddress.Parse("127.0.0.1"),
                //This is the port that the socks proxy lives on (ex: Tor / Tor Browser, Tor is 9150)
                9150,
                //This Can be Socks4 or Socks5
                ProxyConfig.SocksVersion.Five
                ));
            Enumerable.Range(0, count).ToList().ForEach(new Action<int>(x =>
            {
                if (x != 0) Thread.Sleep(6000);
                WebClient client = new WebClient();
                //client.Proxy = proxy.IsActive() ? proxy : null;
                client.Proxy = proxy;
                var doc = new HtmlAgilityPack.HtmlDocument();
                var html = client.DownloadString(url);
                doc.LoadHtml(html);
                var nodes = doc.DocumentNode.SelectNodes("//p/strong");
                IPAddress ip;
                foreach(var node in nodes)
                {
                    if(IPAddress.TryParse(node.InnerText, out ip))
                    {

                        lock (locker)
                        {
                            Console.WriteLine(x + ":::::::::::::::::::::");
                            Console.WriteLine("");
                            if (html.Contains("Congratulations. This browser is configured to use Tor."))
                                Console.WriteLine("Connected through Tor with IP: " + ip.ToString());
                            else
                                Console.Write("Not connected through Tor with IP: " + ip.ToString());
                            Console.WriteLine("");
                            Console.WriteLine(x + ":::::::::::::::::::::");
                        }
                        return;
                    }
                }

                lock (locker)
                {
                    Console.WriteLine(x + ":::::::::::::::::::::");
                    Console.WriteLine("");
                    Console.Write("IP not found");
                    Console.WriteLine("");
                    Console.WriteLine(x + ":::::::::::::::::::::");
                }

            }));
        }
        public static bool probeResponse(string responseFromServer)
        {
            bool ret = false;

            try
            {
                HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
                responseFromServer = Regex.Replace(responseFromServer, @"( |\t|\r?\n)\1+", "$1");
                htmlDoc.LoadHtml(responseFromServer);

                if (htmlDoc.ParseErrors != null && htmlDoc.ParseErrors.Count() > 0)
                {
                    return ret;

                }
                else
                {
                    if (htmlDoc.DocumentNode != null)
                    {
                        foreach (var node in htmlDoc.DocumentNode.Descendants())
                        {
                            if (node.InnerText.Contains("alert('XSSVul')") && !node.HasChildNodes)
                            {
                                if (AttackStrings.checkTags.Contains(node.ParentNode.Name.ToLower()))
                                {
                                    Console.WriteLine("Found in inner text: " + node.ParentNode.Name);
                                    return true;
                                }

                            }
                            if (node.HasAttributes)
                            {
                                foreach (var attr in node.Attributes)
                                {
                                    if (attr.Value.Contains("alert('XSSVul')") && AttackStrings.checkTags.Contains(attr.Name.ToLower()))
                                    {
                                        Console.WriteLine("Found in attr: " + attr.Value);
                                        return true;
                                    }
                                }
                            }
                        }

                    }
                }
            }

            catch (Exception ex)
            {
                string innerMessage =
                (ex.InnerException != null) ?
                ex.InnerException.Message : String.Empty;
                Console.WriteLine("{0}\n{1}", ex.Message, innerMessage);
            }

            return ret;
        }
        internal override string GetUpdatedFilterDefinition()
        {
            //validate
            HtmlAgilityPack.HtmlDocument d = new HtmlAgilityPack.HtmlDocument();
            d.LoadHtml("<html></html>");
            HtmlAgilityPack.HtmlNodeCollection nc = d.DocumentNode.SelectNodes(XpathBox.Text);

            return XpathBox.Text + "\n" + GroupName.Text;
        }
		public static List<Session> GetSessionList(bool doPartial)
		{
			List<Session> results = new List<Session>();
			int page = 12;

			while(true)
			{
				string url = baseUrl + "/API/WebService.asmx/GetEventSessionsByTopic";
				//string data = String.Concat("{\"eventID\":7,\"pageSize\":10,\"page\":", page, ",\"topicID\":-1,\"searchName\":\"\"}");
				string data = JsonConvert.SerializeObject(new JsonRequest(page));
				string json = string.Empty;

				json = WebHelper.HttpPost(url, data);
				var j = JObject.Parse(json);

				HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
				doc.LoadHtml(j["d"]["ReturnText"].ToString());

				var nodes = doc.DocumentNode.SelectNodes("//li[@class='eventSessionListItem']");
				if(nodes != null)
				{
					foreach(HtmlAgilityPack.HtmlNode node in nodes)
					{
						Session session = new Session();
						session.Title = node.SelectSingleNode("div[2]/h3/a").InnerText;
						session.DetailUrl = node.SelectSingleNode("div[2]/h3/a").Attributes["href"].Value;
						var date = node.SelectSingleNode("div[3]/div");
						var time = node.SelectSingleNode("div[3]/div[2]");

						var dateTime = ParseDateTime(date.InnerText, time.InnerText);
						session.Start = dateTime[0];
						session.End = dateTime[1];
						session.Room = HtmlDocHelper.GetInnerText(node, "div[2]/div/ul[@class='ulLocations']");
						session.SpeakerNames = HtmlDocHelper.GetInnerText(node, "div[2]/div[@class='eventSessionSpeakers']/ul");

						results.Add(session);
					}
				}
				else
				{
					break;
				}
				page++;

				if(doPartial) break;
			}

			results = GetExtendedSessions(results);

			foreach(var result in results)
			{
				result.SpeakerList = GetExtendedSpeakers(result.SpeakerList);
			}

			return results;
		}
        private void startHtml(Pagename page)
        {
            HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
            htmlDoc.LoadHtml(page.extract);
            IEnumerable <HtmlAgilityPack.HtmlNode> forms;

            //      forms = htmlDoc.DocumentNode.Descendants("h");
            //     List<HtmlAgilityPack.HtmlNode> h = forms.ToList();

            //       forms = htmlDoc.DocumentNode.Descendants("h1");
            //      List<HtmlAgilityPack.HtmlNode> h1 = forms.ToList();

//            forms = htmlDoc.DocumentNode.Descendants("h2");
//          List<HtmlAgilityPack.HtmlNode> h2 = forms.ToList();

            //          forms = htmlDoc.DocumentNode.Descendants("h3");
            //         List<HtmlAgilityPack.HtmlNode> h3 = forms.ToList();

            forms = htmlDoc.DocumentNode.Descendants("p");
            List <HtmlAgilityPack.HtmlNode> p = forms.ToList();

//            forms = htmlDoc.DocumentNode.Descendants("p1");
//          List<HtmlAgilityPack.HtmlNode> p1 = forms.ToList();
        }
        private bool AnalyseSourceCode()
        {
            // Find images URls in page source code by selecting nodes (thx to HtmlAgilityPack)
            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            doc.LoadHtml(this.BoardSourceCode.Text);

            // Declare forbiden images names list
            var forbiden = new List <string> {
                "avatars", "default", "api", "upload"
            };

            var itemList = doc.DocumentNode.SelectNodes("//img").ToList();

            foreach (HtmlAgilityPack.HtmlNode x in itemList)
            {
                if (!forbiden.Any(f => x.Attributes["src"].Value.Contains(f)))
                {
                    this.ThumbnailImages.Add(new PinterestImage(x.Attributes["src"].Value));
                }
            }

            // Find images URls in page source code with regulary expression

            /*Regex regx = new Regex("http://([\\w+?\\.\\w+])+([a-zA-Z0-9\\~\\!\\@\\#\\$\\%\\^\\&amp;\\*\\(\\)_\\-\\=\\+\\\\\\/\\?\\.\\:\\;\\'\\,]*)?", RegexOptions.IgnoreCase);
             * MatchCollection matches = regx.Matches(this.BoardSourceCode.Text);
             *
             * foreach (Match match in matches)
             * {
             *  if (!exist(this.Images, match.Value) && match.Value.EndsWith(".jpg"))
             *  {
             *      this.Images.Add(match.Value.Replace("236x", "originals"));
             *      this.ImagesListView.Items.Add(match.Value.Replace("236x", "originals"));
             *  }
             * }*/
            return(true);
        }
Exemple #33
0
        void CheckGrammar()
        {
            try
            {
                string html = ParseResponse(GetRequest(tbInput.Text.Replace("\r\n", "\n")));

                HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                doc.LoadHtml(html);

                foreach (var node in doc.DocumentNode.ChildNodes)
                {
                    if (node.Name == "em")
                    {
                        string color = node.Attributes["class"].Value;
                        color = color.Remove(color.Length - 5);

                        tbOuput.AppendText(node.InnerText, GetColor(color));
                    }
                    else if (node.Name == "br")
                    {
                        tbOuput.AppendText("\r\n");
                    }
                    else if (node.Name == "#text")
                    {
                        tbOuput.AppendText(node.InnerText, Colors.Black);
                    }
                }
            }
            catch (Exception ex)
            {
            }
            if (timer.IsEnabled)
            {
                timer.Stop();
            }
        }
Exemple #34
0
        public int getSumPages()
        {
            string positive_link   = getParameterLink(getSource(getUserLink()), positive);
            string negative_link   = getParameterLink(getSource(getUserLink()), negative);
            string positive_source = getSource(positive_link);
            string negative_source = getSource(positive_link);

            //List<string> res = searchPage(param_source, parameter);
            HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
            htmlDoc.LoadHtml(positive_source);
            HtmlAgilityPack.HtmlNode pagination     = htmlDoc.DocumentNode.SelectSingleNode("//body").SelectSingleNode("//div[@id='CentralArea']").SelectSingleNode("//div[@class='newPagination']");
            HtmlAgilityPack.HtmlNode pgn_pagination = pagination.SelectSingleNode("//b[@id='PGN_pagination1']");
            Regex max_page_regex = new Regex(@">(\d+)</a></b>");
            int   max_pages      = Int32.Parse(max_page_regex.Match(pgn_pagination.WriteTo()).Groups[1].ToString());

            SUM_OF_PAGES += max_pages;
            htmlDoc       = new HtmlAgilityPack.HtmlDocument();
            htmlDoc.LoadHtml(negative_source);
            pagination     = htmlDoc.DocumentNode.SelectSingleNode("//body").SelectSingleNode("//div[@id='CentralArea']").SelectSingleNode("//div[@class='newPagination']");
            pgn_pagination = pagination.SelectSingleNode("//b[@id='PGN_pagination1']");
            max_pages      = Int32.Parse(max_page_regex.Match(pgn_pagination.WriteTo()).Groups[1].ToString());
            SUM_OF_PAGES  += max_pages;
            return(SUM_OF_PAGES);
        }
Exemple #35
0
        private void Find_Data()
        {
            IList <IWebElement> searchElements = driver.FindElements(By.TagName("tbody"));

            foreach (IWebElement i in searchElements)
            {
                HtmlAgilityPack.HtmlDocument htmlDocument = new HtmlAgilityPack.HtmlDocument();
                var text = i.GetAttribute("innerHTML");

                htmlDocument.LoadHtml(text);
                var inputs = htmlDocument.DocumentNode.Descendants("tr").ToList();
                foreach (var items in inputs)
                {
                    HtmlAgilityPack.HtmlDocument htmlDocument1 = new HtmlAgilityPack.HtmlDocument();
                    htmlDocument1.LoadHtml(items.InnerHtml);
                    var tds = htmlDocument1.DocumentNode.Descendants("td").ToList();
                    if (tds.Count != 0)
                    {
                        Text_Results.AppendText(tds[0].InnerText + "   " + tds[1].InnerText + "   " + tds[2].InnerText + "   " + "\t\r");
                    }
                }
                Text_Results.AppendText("\t\r");
            }
        }
        public override List <Movie> searchMovie(string tmp_title)
        {
            var target  = new Uri(retrieveLink() + "searching/" + tmp_title + ".html");
            var handler = new ClearanceHandler("http://localhost:8191/")
            {
                UserAgent  = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36",
                MaxTimeout = 60000
            };
            var          client = new HttpClient(handler);
            List <Movie> tmp    = new List <Movie>();

            try
            {
                var content = client.GetStringAsync(target).Result;
                HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
                htmlDoc.LoadHtml(content);

                return(tmp);
            }
            catch (Exception ex)
            {  }

            return(null);
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            // 例えば ConverterParameter=true とすると、parameter に string "true" が入ります。
            if (value == null)
            {
                return("");
            }

            // HtmlAgilityPack を使用してタグ付きの string からタグを除去します。
            var hap = new HtmlAgilityPack.HtmlDocument();

            hap.LoadHtml(value.ToString());
            var doc = hap.DocumentNode.InnerText;

            doc = doc.Replace(@"&nbsp;", " ").Replace(@"&lt;", "<").Replace(@"&gt;", ">").Replace(@"&amp;", "&").Replace(@"&quot;", "\"");

            var multiCRRegex = new Regex(@"\n\n\n+");

            doc = multiCRRegex.Replace(doc, "\n\n");

            // parameter には数字が入りますので、数値があればその文字数でカットした string を返します。
            int strLength;

            if (int.TryParse(parameter as string, out strLength))
            {
                if (doc.Length > strLength)
                {
                    return(doc.Substring(0, strLength) + "…");
                }
                return(doc);
            }
            else
            {
                return(doc);
            }
        }
Exemple #38
0
        public static List <string> FindAllHrefs(string text)
        {
            var empty = new List <string>();

            if (string.IsNullOrEmpty(text))
            {
                return(empty);
            }

            try
            {
                HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                doc.LoadHtml(text);

                var result = doc.DocumentNode.SelectNodes("//a")
                             ?.Select(p => p.GetAttributeValue("href", ""))
                             ?.Where(s => !string.IsNullOrEmpty(s))
                             ?.ToList();

                return(result ?? empty);
            }
            catch { }
            return(empty);
        }
Exemple #39
0
        private string ParseHtmlString(string htmlString)
        {
            var result = string.Empty;

            var htmlDoc = new HtmlAgilityPack.HtmlDocument();

            htmlDoc.LoadHtml(htmlString);

            if (htmlDoc.DocumentNode == null)
            {
                return(result);
            }

            if (htmlDoc.DocumentNode.SelectSingleNode("//p[2]") != null) //onliner
            {
                result = htmlDoc.DocumentNode.SelectSingleNode("//p[2]").InnerText;
            }
            else if (htmlDoc.DocumentNode.InnerText != null)
            {
                result = htmlDoc.DocumentNode.InnerText;
            }

            return(result);
        }
Exemple #40
0
        public static HtmlAgilityPack.HtmlDocument SendGetReq(Account acc, string url)
        {
            acc.Wb.RestClient.BaseUrl         = new Uri(acc.AccInfo.ServerUrl);
            acc.Wb.RestClient.CookieContainer = HttpHelper.GetCookies(acc);

            var req = new RestRequest
            {
                Resource = url,
                Method   = Method.GET,
            };

            var response = acc.Wb.RestClient.Execute(req);

            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new Exception("SendGetReq failed!" + response.StatusCode);
            }

            var htmlDoc = new HtmlAgilityPack.HtmlDocument();

            htmlDoc.LoadHtml(response.Content);

            return(htmlDoc);
        }
Exemple #41
0
        /// <summary>
        /// 从HTML中找到所有值为innertext的链接
        /// |tagname|可以是a,img
        /// </summary>
        /// <returns></returns>
        public static List <string> GetHrefs(string htmlbody, string ElementId, string tagname, string attribute)
        {
            List <string> hrefList = new List <string>();

            var doc = new HtmlAgilityPack.HtmlDocument();

            doc.LoadHtml(htmlbody);
            var alist = doc.DocumentNode.Descendants(tagname);

            foreach (var htmlNode in alist)
            {
                if (htmlNode.Id == ElementId)
                {
                    string activZfbLink1 = "";
                    var    htmlAttribute = htmlNode.Attributes[attribute];
                    if (htmlAttribute != null)
                    {
                        activZfbLink1 = htmlAttribute.Value;
                    }
                    hrefList.Add(activZfbLink1);
                }
            }
            return(hrefList);
        }
        public override bool retrieveStreamLinks(Movie movie)
        {
            var target  = movie.getMoviePageLink();
            var handler = new ClearanceHandler("http://localhost:8191/")
            {
                UserAgent  = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36",
                MaxTimeout = 60000
            };
            var client = new HttpClient(handler);

            try
            {
                //Load Main Page
                var content = client.GetStringAsync(target);
                HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
                htmlDoc.LoadHtml(content.Result);
                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.InnerException.Message);
                return(false);
            }
        }
Exemple #43
0
        private string retrieveLink()
        {
            if (actual_url == null)
            {
                try
                {
                    IWebProxy defWebProxy = WebRequest.DefaultWebProxy;
                    defWebProxy.Credentials = CredentialCache.DefaultCredentials;

                    WebClient test = new WebClient {
                        Proxy = defWebProxy
                    };
                    var extr = test.DownloadString("https://www.cb01.community/");
                    HtmlAgilityPack.HtmlDocument doctodown = new HtmlAgilityPack.HtmlDocument();
                    doctodown.LoadHtml(extr);
                    actual_url = doctodown.DocumentNode.SelectNodes("/html/body/div/h2/a/b")[0].InnerText;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            return(actual_url);
        }
Exemple #44
0
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
        public async Task <JsonResult> Vakitler(string id)
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
        {
            _urlVakit = _urlVakit + id + "-namaz-vakitleri";
            HtmlAgilityPack.HtmlDocument htmldoc = new HtmlAgilityPack.HtmlDocument();
            htmldoc.LoadHtml(GetContent(_urlVakit));
            var imsak   = htmldoc.DocumentNode.SelectNodes("//*[@id=\"time1\"]");
            var gunes   = htmldoc.DocumentNode.SelectNodes("//*[@id=\"time2\"]");
            var oglen   = htmldoc.DocumentNode.SelectNodes("//*[@id=\"time3\"]");
            var ikinidi = htmldoc.DocumentNode.SelectNodes("//*[@id=\"time4\"]");
            var aksam   = htmldoc.DocumentNode.SelectNodes("//*[@id=\"time5\"]");
            var yatsi   = htmldoc.DocumentNode.SelectNodes("//*[@id=\"time6\"]");

            var vakit = new VakitModel();

            vakit.Imsak  = imsak[0].InnerHtml;
            vakit.Gunes  = gunes[0].InnerHtml;
            vakit.Ikindi = ikinidi[0].InnerHtml;
            vakit.Oglen  = oglen[0].InnerHtml;
            vakit.Aksam  = aksam[0].InnerHtml;
            vakit.Yatsi  = yatsi[0].InnerHtml;

            return(Json(vakit));
        }
Exemple #45
0
        public static Takvim GetTakvim(string HTML)
        {
            var Pagenationx = new Pagenation();

            HtmlAgilityPack.HtmlDocument Document = new HtmlAgilityPack.HtmlDocument();
            Document.LoadHtml(HTML);

            var Table     = Document.DocumentNode.SelectSingleNode("/html/body/main/div[4]/table");
            var Gunler    = Table.SelectNodes("thead/tr/td");
            var Icerikler = Table.SelectNodes("tbody/tr/td");

            var Donut = new Takvim();

            Donut.TakvimListe = new List <TakvimBirGun>();
            for (int i = 0; i < Gunler.Count; i++)
            {
                var Gun    = Gunler[i];
                var Icerik = Icerikler[i].SelectNodes("a");

                var TBirGun = new TakvimBirGun();
                TBirGun.Gün     = Gun.InnerText;
                TBirGun.Diziler = new List <TakvimDizi>();

                foreach (var SIcerik in Icerik)
                {
                    TBirGun.Diziler.Add(new TakvimDizi()
                    {
                        Dizi = SIcerik.InnerText
                    });
                }

                Donut.TakvimListe.Add(TBirGun);
            }

            return(Donut);
        }
Exemple #46
0
        public static List <AnimalRecord> ParseRecords(string dataPath, string[] filenames)
        {
            string[] files = new string[filenames.Length];
            for (int i = 0; i < filenames.Length; i++)
            {
                files[i] = dataPath + "\\" + filenames[i];
            }
            List <AnimalRecord> records = new List <AnimalRecord>();

            foreach (string f in files)
            {
                StreamReader reader = new StreamReader(f);
                string       html   = reader.ReadToEnd();
                reader.Close();
                HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                doc.LoadHtml(html);
                AnimalRecord r = AnimalRecord.HtmlDocumentToAnimalRecord(doc);
                if (r != null)
                {
                    records.Add(r);
                }
            }
            return(records);
        }
Exemple #47
0
        public static List <RatingSubject> GetRating(string studnumber, string paspnumber)
        {
            string url = $"https://www.isuct.ru/student/rating/view?paspnumber={paspnumber}&studnumber={studnumber}";

            using (var httpClient = new HttpClient())
            {
                var content  = new List <RatingSubject>();
                var response = httpClient.GetStringAsync(url).Result;
                var html     = new HtmlAgilityPack.HtmlDocument();
                html.LoadHtml(response);
                var nodeCollection = html.DocumentNode.SelectNodes("//tr");

                foreach (var node in    nodeCollection)
                {
                    //var childNodes = node.ChildNodes;
                    var childNodeArr = node.ChildNodes.ToArray();
                    var subject      = new RatingSubject();

                    subject.Semester             = childNodeArr[0].InnerText;
                    subject.SubjectName          = childNodeArr[1].InnerText;
                    subject.Type                 = childNodeArr[2].InnerText;
                    subject.FinalScore           = childNodeArr[3].InnerText;
                    subject.Term                 = childNodeArr[4].InnerText;
                    subject.FirstCheckPointScore = childNodeArr[5].InnerText;
                    subject.NumberOfAbsenteeismAtTheFirstCheckpoint = childNodeArr[6].InnerText;
                    subject.SecondCheckPointScore = childNodeArr[7].InnerText;
                    subject.NumberOfAbsenteeismAtTheSecondCheckpoint = childNodeArr[8].InnerText;
                    subject.ThirdCheckPointScore = childNodeArr[9].InnerText;
                    subject.NumberOfAbsenteeismAtTheThirdCheckpoint = childNodeArr[10].InnerText;

                    content.Add(subject);
                }
                content.RemoveAt(0); // это список предметов
                return(content);
            }
        }
Exemple #48
0
        public void ExtractSingle_A_Element()
        {
            var folderName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Misc");
            var fileName   = Path.Combine(folderName, "OneParagraphWithOne_A_Element.eml");

            var expectedLink = @"<a href=""https://www.google.com"">Google</a>";

            // remove any .msg files for a clean test
            Cleaner cleaner = new Cleaner();

            cleaner.Messages(folderName);

            // get count of .eml files (should be one)
            int emlCount = folderName.EmlFileCount();

            // convert the .eml file to .msg
            var ops = new FromEml();

            ops.EmlToMessageFiles(folderName);

            // get information from the single .msg file created from the .eml file
            var singleMailInformation = ops.GetMailInformation(folderName).FirstOrDefault();

            var toAddress = singleMailInformation.ToRecipients.FirstOrDefault();

            Assert.AreEqual(4, singleMailInformation.ToRecipients.Count(), "Expected four to addresses");
            Assert.AreEqual(2, singleMailInformation.CCRecipients.Count(), "Expected two cc addresses");

            HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
            htmlDoc.LoadHtml(singleMailInformation.BodyAsHTML);

            // Validate the link
            Assert.IsTrue(
                htmlDoc.DocumentNode.ChildNodes.FirstOrDefault()
                .ChildNodes.FirstOrDefault().NextSibling.OuterHtml == expectedLink);
        }
        private List <string> FindAllAppKeysId(string htmlContent, string keyName = null)
        {
            List <string> htmlValues = new List <string>();

            HtmlAgilityPack.HtmlDocument htmlDocument = new HtmlAgilityPack.HtmlDocument();
            htmlDocument.LoadHtml(htmlContent);

            HtmlAgilityPack.HtmlNode node = htmlDocument.DocumentNode.SelectSingleNode("//div[contains(@class, 'ui key list')]");

            HtmlAgilityPack.HtmlNodeCollection nodes = node.ChildNodes;

            foreach (HtmlAgilityPack.HtmlNode keyNode in nodes)
            {
                if (keyNode.OuterHtml.Contains(keyName == null ? "AltinnStudioAppKey" : keyName))
                {
                    // Returns the button node
                    HtmlAgilityPack.HtmlNode deleteButtonNode = keyNode.SelectSingleNode("./div/button");
                    string dataId = deleteButtonNode.GetAttributeValue("data-id", string.Empty);
                    htmlValues.Add(dataId);
                }
            }

            return(htmlValues);
        }
 public static void CheckUpdate(string assemblyVersion)
 {
     try
     {
         WebClient webClient = new WebClient();
         HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
         document.LoadHtml(webClient.DownloadString("https://wr-rainforest.github.io/Naver-Webtoon-Downloader/info/latest_version.html"));
         //document.LoadHtml(webClient.DownloadString("https://wr-rainforest.github.io/Naver-Webtoon-Downloader/Properties/version.latest.build.txt"));
         Version latestVersion = new Version(document.DocumentNode.SelectSingleNode("/html/body").InnerText);
         if (string.IsNullOrEmpty(document.DocumentNode.SelectSingleNode("/html/body").InnerText))
         {
             throw new Exception();
         }
         Version currentVersion = new Version(assemblyVersion);
         int     compareResult  = currentVersion.CompareTo(latestVersion);
         if (compareResult < 0)
         {
             IO.Print("\r\n");
             IO.Print($"*$$새로운 버전이 출시되었습니다. v{latestVersion.Major}.{latestVersion.Minor} (빌드 {latestVersion.Build}.{latestVersion.Revision})$cyan$");
             IO.Print($"*$$업데이트 다운로드 : https://github.com/wr-rainforest/Naver-Webtoon-Downloader/releases/tag/v{latestVersion}$cyan$");
             IO.Print("");
         }
         else if (compareResult == 0)
         {
             IO.Print(" ($$최신 버전입니다.$blue$)");
         }
         else
         {
             IO.Print(" ($$개발 버전$blue$)");
         }
     }
     catch
     {
         IO.Print("\r\n $$버전 업데이트를 확인할 수 없습니다.$red$");
     }
 }
Exemple #51
0
        public override IEnumerable <AbstractBookInfo> DoWork()
        {
            string url = string.Format(BaseUrl, "1");
            //得到最大的页码
            int MaxPageNum = 1;

            //初始化一个DOM
            HtmlAgilityPack.HtmlDocument dom = new HtmlAgilityPack.HtmlDocument();
            dom.LoadHtml(url.GetWeb());

            //内容
            HtmlAgilityPack.HtmlNode listContent = dom.GetElementbyId("CrListTitle");

            //得到分页
            HtmlAgilityPack.HtmlNode pagesNode = dom.GetElementbyId("CrListPage");


            //得到最大页码
            MaxPageNum = GetMaxPageNum(pagesNode);

            IEnumerable <AbstractBookInfo> AllBooks = GetBooks(MaxPageNum, GetPageBooks);

            return(AllBooks);
        }
        private static List <IchibaItem> ParseIchibaHtml(string html)
        {
            var htmlDocument = new HtmlAgilityPack.HtmlDocument();

            htmlDocument.LoadHtml(html);

            var root = htmlDocument.DocumentNode;
            List <IchibaItem> items = new List <IchibaItem>();

            var ichibaMainNode      = root.FirstChild;
            var ichiba_mainitemList = ichibaMainNode.GetElementsByClassName("ichiba_mainitem");

            foreach (var itemNode in ichiba_mainitemList)
            {
                try
                {
                    var item = IchibaItemFromXmlNode(itemNode);
                    items.Add(item);
                }
                catch { }
            }

            return(items);
        }
        public static async Task <decimal?> GetExchangeSellingRateAsync(string currencyName)
        {
            using var httpClient = new HttpClient();
            string html = await httpClient.GetStringAsync("https://www.boc.cn/sourcedb/whpj/sjmfx_1621.html").ConfigureAwait(false);

            var doc = new HtmlAgilityPack.HtmlDocument();

            doc.LoadHtml(html);
            var nodes    = doc.DocumentNode.SelectNodes("/html/body/article/div/table/tbody/tr");
            var currency = nodes.Select(n => new
            {
                Name         = n.SelectSingleNode("td[1]").InnerText,
                ExchangeBuy  = n.SelectSingleNode("td[2]").InnerText,
                CashBuy      = n.SelectSingleNode("td[3]").InnerText,
                ExchangeSell = n.SelectSingleNode("td[4]").InnerText,
                CashSell     = n.SelectSingleNode("td[5]").InnerText,
            }).FirstOrDefault(i => currencyName.Equals(i.Name, StringComparison.OrdinalIgnoreCase));

            return(currency is null
                ? null
                : decimal.TryParse((string)currency.ExchangeSell, out var rate)
                ? rate / 100
                : null);
        }
        public async Task <List <UpdateChannel> > DownloadVersionsFromWebSite()
        {
            var lstReturn       = new List <UpdateChannel>();
            var ccUpdateChannel = new UpdateChannel()
            {
                Name    = "Current",
                Updates = new List <Update>()
            };
            var dcUpdateChannel = new UpdateChannel()
            {
                Name    = "Deferred",
                Updates = new List <Update>()
            };
            var frdcUpdateChannel = new UpdateChannel()
            {
                Name    = "FirstReleaseDeferred",
                Updates = new List <Update>()
            };

            lstReturn.Add(ccUpdateChannel);
            lstReturn.Add(dcUpdateChannel);
            lstReturn.Add(frdcUpdateChannel);

            var webClient = new WebClient();
            var page      = await webClient.DownloadStringTaskAsync(OfficeVersionWebSite);

            var doc = new HtmlAgilityPack.HtmlDocument();

            doc.LoadHtml(page);

            var tables = doc.DocumentNode.SelectNodes("//table").ToList();

            foreach (var table in tables)
            {
                var headerRow = table
                                .Descendants("tr")
                                .Where(tr => tr.Elements("th").Count() > 1)
                                .Select(tr => tr.Elements("th").Select(td => td.InnerText.Trim()).ToList())
                                .FirstOrDefault();
                if (headerRow == null)
                {
                    continue;
                }
                if (headerRow[0].ToLower() != "version")
                {
                    continue;
                }

                var rows = table
                           .Descendants("tr")
                           .Where(tr => tr.Elements("td").Count() > 1)
                           .Select(tr => tr.Elements("td").Select(td => td.InnerText.Trim()).ToList())
                           .ToList();
                if (rows.Count == 0)
                {
                    continue;
                }

                var ccIndex   = 1;
                var frdcIndex = 2;
                var dcIndex   = 3;
                for (var i = 1; i <= 3; i++)
                {
                    var rowHeader = headerRow[i];
                    if (rowHeader.ToLower().Contains("current"))
                    {
                        ccIndex = i;
                    }
                    if (rowHeader.ToLower().Contains("deferred") &&
                        rowHeader.ToLower().Contains("first release"))
                    {
                        frdcIndex = i;
                    }
                    if (rowHeader.ToLower().Contains("deferred") &&
                        !rowHeader.ToLower().Contains("first release"))
                    {
                        dcIndex = i;
                    }
                }

                foreach (var row in rows)
                {
                    var version = row[0];
                    if (!Regex.Match(version, @"\d{4}").Success)
                    {
                        continue;
                    }

                    var currentChannel = row[ccIndex];
                    var ccVersions     = Regex.Matches(currentChannel, @"\d{4}\.\d{4}\s");
                    if (ccVersions.Count == 0)
                    {
                        continue;
                    }

                    var frdc         = row[frdcIndex];
                    var frdcVersions = Regex.Matches(frdc, @"\d{4}\.\d{4}");
                    if (frdcVersions.Count == 0)
                    {
                        continue;
                    }

                    var dc         = row[dcIndex];
                    var dcVersions = Regex.Matches(dc, @"\d{4}\.\d{4}");
                    if (dcVersions.Count == 0)
                    {
                        continue;
                    }

                    foreach (Match build in ccVersions)
                    {
                        ccUpdateChannel?.Updates.Add(new Update()
                        {
                            Build         = build.Value,
                            LegacyVersion = "16.0." + build.Value,
                            Version       = version
                        });
                    }

                    foreach (Match build in dcVersions)
                    {
                        dcUpdateChannel?.Updates.Add(new Update()
                        {
                            Build         = build.Value,
                            LegacyVersion = "16.0." + build.Value,
                            Version       = version
                        });
                    }

                    foreach (Match build in dcVersions)
                    {
                        frdcUpdateChannel?.Updates.Add(new Update()
                        {
                            Build         = build.Value,
                            LegacyVersion = "16.0." + build.Value,
                            Version       = version
                        });
                    }
                }
            }

            return(lstReturn);
        }
        private async void btn_StartDishPrice_Click(object sender, RoutedEventArgs e)
        {
            if (cityList.Count == 0)
            {
                ShowStep2StatusText("请先获取城市列表");
                return;
            }

            ShowStep2StatusText($"正在从{cityList.Count}个城市获取私房菜价格");

            //这里只是简单的示例,所以仅抓取第一页数据
            //需要添加以下Cookie信息,否则会出现验证码页面
            var url          = "";
            var originalHtml = "";
            var html         = "";
            var userAgent    = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36";
            var accept       = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8";
            var r            = new Random();

            ClearRecord();

            //PC页面价格加密了,访问移动端页面来获取价格
            foreach (var item in cityList)
            {
                ShowStep2StatusText($"开始获取{item.CityName}私房菜价格");
                //等待10-20秒
                await Task.Delay(r.Next(10, 20) *1000);

                url = UrlUtil.DianpingHomeDishes.Replace("citypyname", item.CityPinYinName);
                //移动端
                url = url.Replace("www", "m");
                var cookieContainer = GetCityCookies(item.CityID);
                originalHtml = await WebUtil.GetHtmlSource(url, accept, userAgent, Encoding.UTF8, cookieContainer);

                var match = RegexUtil.RegexMatch(originalHtml, RegexPattern.DianPingContentArea);

                if (match.Success == false)
                {
                    continue;
                }

                //正则暂时不好匹配,使用HtmlAgilityPack
                //图片是动态的,不打算使用CEF,这里就不抓取了
                html = "<html><head></head><body >" + match.Value + "</body></html>";
                HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                doc.LoadHtml(html);
                var itemList  = doc.DocumentNode.SelectNodes("//li");
                var titleList = doc.DocumentNode.SelectNodes("//h3");

                if (itemList.Count != titleList.Count)
                {
                    continue;
                }

                for (int i = 0; i < itemList.Count; i++)
                {
                    var shopName       = titleList[i].InnerText;
                    var keyword        = itemList[i].InnerText;
                    var averageConsume = RegexUtil.ExtractDianPingAveragePrice(keyword);

                    Result result = new Result()
                    {
                        AverageSpend   = averageConsume,
                        CityID         = item.CityID,
                        Html           = originalHtml,
                        RestaurentName = shopName,
                        Keyword        = keyword
                    };

                    await SaveResult(result);

                    ShowStep2StatusText(result.ToString());
                }
            }
        }
Exemple #56
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(richTextBox1.Text))
            {
                FuncMsg.Warn("请输入要发布的内容");
                return;
            }
            ;

            var orders = richTextBox1.Text.Split('\n');

            if (orders.Length < 12)
            {
                FuncMsg.Warn("数据填写不全,请补全后重新提交!");
                return;
            }
            DataSource = new JObject();

            var baseUrl = "http://www.012395.com/e/DoInfo/AddInfo.php?mid=15&enews=MAddInfo&classid=115&Submit=%E6%B7%BB%E5%8A%A0%E4%BF%A1%E6%81%AF";

            var response = ApiClient.AddInfo(baseUrl);

            if (response == FuncConst.AddErr)
            {
                FuncMsg.Error($"{FuncConst.AddErr}\r\n{FuncConst.NetworkErr}");
                return;
            }

            HtmlAgilityPack.HtmlDocument html = new HtmlAgilityPack.HtmlDocument();
            html.LoadHtml(response);

            if (!IsLogin(html))
            {
                return;
            }

            DataSource.Add("enews", GetNodeVal(html, "enews"));
            DataSource.Add("classid", GetNodeVal(html, "classid"));
            DataSource.Add("id", "");
            DataSource.Add("filepass", GetNodeVal(html, "filepass"));
            DataSource.Add("mid", "15");
            DataSource.Add("tokenid", "");

            if (chkSimple.Checked)
            {
                SimpleModel(orders);
            }
            else
            {
                StandardModel(orders);
            }

            var postUrl = "http://www.012395.com/e/DoInfo/ecms.php";

            var result = ApiClient.SaveInfo(postUrl, DataSource);

            if (IsSuccess(result))
            {
                FuncMsg.Info($"货源信息:[{DataSource["title"].ToString()}]发布成功!");
                RefreshLately();
                if (chkSimple.Checked)
                {
                    richTextBox2.Visible = true;
                    SwitchSimpleModel();
                }
                else
                {
                    richTextBox2.Visible = false;
                    SwitchStandardModel();
                }
            }
        }
Exemple #57
0
        private static List <Work> FormatWorks(List <ResumeWork> sources, string attr, string resumeId, string tag)
        {
            if (sources == null)
            {
                return(null);
            }

            var   works = new List <Work>();
            short index = 1;

            sources.ForEach(t =>
            {
                var document = new HtmlAgilityPack.HtmlDocument();

                var str = t.Industry;

                var industry = "0x0";

                if (!string.IsNullOrEmpty(str))
                {
                    str = str.Split(',')[0];
                    str = str.Replace(" ", "");
                    document.LoadHtml(File.ReadAllText(Application.StartupPath + "\\XML\\Industry" + tag + ".xml"));

                    industry = document.DocumentNode.SelectSingleNode("nodes[1]/node[@" + attr + " = '" + str + "']")?.Attributes["result-key"]?.Value;
                }
                industry = industry ?? "0x0";

                str = t.Nature;

                var nature = "*";

                if (!string.IsNullOrEmpty(str))
                {
                    document.LoadHtml(File.ReadAllText(Application.StartupPath + "\\XML\\CompanyType" + tag + ".xml"));

                    var node = document.DocumentNode.SelectSingleNode("nodes[1]/node[@" + attr + " = '" + str + "']");

                    if (node != null)
                    {
                        nature = node.Attributes["result-key"].Value;
                    }
                }

                str = t.Size;

                var size = "*";

                if (!string.IsNullOrEmpty(str))
                {
                    document.LoadHtml(File.ReadAllText(Application.StartupPath + "\\XML\\CompanySize" + tag + ".xml"));

                    var node = document.DocumentNode.SelectSingleNode("nodes[1]/node[@" + attr + " = '" + str + "']");
                    if (node != null)
                    {
                        size = node.Attributes["result-key"].Value;
                    }
                }

                works.Add(new Work
                {
                    ResumeId    = resumeId,
                    Id          = index,
                    Begin       = DateTime.Parse(t.Begin),
                    End         = string.IsNullOrEmpty(t.End.Trim()) || t.End == "0" || t.End.IndexOf("至今", StringComparison.Ordinal) > -1 ? DateTime.MaxValue : DateTime.Parse(t.End),
                    Company     = t.Company,
                    Industry    = short.Parse(industry.Replace("0x", ""), System.Globalization.NumberStyles.HexNumber),
                    Size        = size.ToCharArray().First(),
                    Nature      = nature.ToCharArray().First(),
                    Department  = t.Department,
                    Position    = t.Position,
                    Description = t.Description
                });
                index++;
            });

            return(works);
        }
        void document_MouseDown(object sender, System.Windows.Forms.HtmlElementEventArgs e)
        {
            try
            {
                if (e.MouseButtonsPressed == System.Windows.Forms.MouseButtons.Right)
                {
                    System.Windows.Forms.HtmlElement element = this.automation_browser.Document.GetElementFromPoint(e.ClientMousePosition);

                    //System.Windows.Forms.HtmlElement xPath_element = this.automation_browser.Document.GetElementFromPoint(e.ClientMousePosition);



                    //******************* for testing XPATH *****************



                    var savedId  = element.Id;
                    var uniqueId = Guid.NewGuid().ToString();
                    element.Id = uniqueId;

                    var doc = new HtmlAgilityPack.HtmlDocument();
                    doc.LoadHtml(element.Document.GetElementsByTagName("html")[0].OuterHtml);
                    element.Id = savedId;

                    var    node  = doc.GetElementbyId(uniqueId);
                    string xpath = node.XPath;



                    string[] parentNodes = xpath.Split('/');

                    parentCounting = 0;

                    try
                    {
                        System.Windows.Forms.HtmlElement starting_element = Finding_Parent_With_Identifier(element);

                        string starting_element_idName = starting_element.GetAttribute("id");

                        string startingPattern = @"//*[@";
                        string middlePattern   = "=" + '"'; //"="";
                        string endingPattern   = '"' + "]"; //""]";

                        string XPATH = startingPattern + "id" + middlePattern + starting_element_idName + endingPattern;

                        for (int i = parentNodes.Length - parentCounting + 1; i < parentNodes.Length; i++)
                        {
                            string tmp = '/' + parentNodes[i];
                            XPATH += tmp;
                        }
                    }
                    catch (Exception ex)
                    {
                    }



                    //******************* for testing XPATH *****************



                    string element_tagName = element.TagName.ToString();
                    //string innerHtml=element.TagName.
                    //string element_outerHTML = element2.OuterHtml;


                    //MessageBox.Show("inner html= " + element.InnerHtml);
                    //MessageBox.Show("inner text= "+ element.InnerText);
                    //MessageBox.Show("class name= "+element.GetAttribute("class").Trim());

                    //MessageBox.Show(element_tagName);


                    //MessageBox.Show("id= "+element.GetAttribute("id"));
                    //MessageBox.Show("name= "+element.GetAttribute("name"));
                    //MessageBox.Show("inner text= " + element.InnerText);
                    //MessageBox.Show("inner html= " + element.InnerHtml);

                    selenium_id = element.GetAttribute("id").Trim();

                    System.Windows.Forms.HtmlElement aelement = automation_browser.Document.GetElementById(selenium_id);


                    // MessageBox.Show(selectedIndex.ToString());

                    //MessageBox.Show(element_tagName);
                    //if (element_tagName.ToLower() == "select")
                    //{
                    selenium_id = element.GetAttribute("id").Trim();
                    if (!input_id_check_str.Contains(selenium_id.ToLower()))
                    {
                        string           msgtext = "Select this Drop-Down?";
                        string           txt     = Application.Current.MainWindow.Title;
                        MessageBoxButton button  = MessageBoxButton.YesNoCancel;
                        MessageBoxResult result  = MessageBox.Show(msgtext, txt, button);

                        switch (result)
                        {
                        case MessageBoxResult.Yes:


                            input_id_check_str.Add(selenium_id.ToLower());
                            selenium_name = element.GetAttribute("name").Trim();

                            object objElement       = element.DomElement;
                            object objSelectedIndex = objElement.GetType().InvokeMember("selectedIndex",
                                                                                        BindingFlags.GetProperty, null, objElement, null);
                            int selectedIndex = (int)objSelectedIndex;

                            // MessageBox.Show("in yes indes= "+selectedIndex);

                            AutomationBrowser_HtmlElementInfo.Add(new HtmlElementInfo()
                            {
                                Html_element_id      = selenium_id,
                                Html_element_name    = selenium_name,
                                Html_drop_down_index = selectedIndex,
                                //Html_element_XPATH = XPATH
                            });



                            //(this.Parent as MetroWindow).DialogResult = true;
                            //(this.Parent as MetroWindow).Close();
                            break;

                        case MessageBoxResult.No:

                            break;

                        case MessageBoxResult.Cancel:

                            break;
                        }
                    }
                    else
                    {
                        //MessageBox.Show("You have already entered value in thid field.");
                    }

                    // }
                    //else
                    //{
                    //    MessageBox.Show("Please, Focus only Drop-Down");
                    //}
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemple #59
0
        public async Task LoadBadgesAsync()
        {
            // Settings.Default.myProfileURL = http://steamcommunity.com/id/USER
            var profileLink = Settings.Default.myProfileURL + "/badges";
            var pages       = new List <string>()
            {
                "?p=1"
            };
            var document   = new HtmlDocument();
            int pagesCount = 1;

            try
            {
                // Load Page 1 and check how many pages there are
                var pageURL  = string.Format("{0}/?p={1}", profileLink, 1);
                var response = await CookieClient.GetHttpAsync(pageURL);

                // Response should be empty. User should be unauthorised.
                if (string.IsNullOrEmpty(response))
                {
                    RetryCount++;
                    if (RetryCount == 18)
                    {
                        ResetClientStatus();
                        return;
                    }
                    throw new Exception("");
                }
                document.LoadHtml(response);

                // If user is authenticated, check page count. If user is not authenticated, pages are different.
                var pageNodes = document.DocumentNode.SelectNodes("//a[@class=\"pagelink\"]");
                if (pageNodes != null)
                {
                    pages.AddRange(pageNodes.Select(p => p.Attributes["href"].Value).Distinct());
                    pages = pages.Distinct().ToList();
                }

                string lastpage = pages.Last().ToString().Replace("?p=", "");
                pagesCount = Convert.ToInt32(lastpage);

                // Get all badges from current page
                ProcessBadgesOnPage(document);

                // Load other pages
                for (var i = 2; i <= pagesCount; i++)
                {
                    lblDrops.Text = string.Format(localization.strings.reading_badge_page + " {0}/{1}, " + localization.strings.please_wait, i, pagesCount);

                    // Load Page 2+
                    pageURL  = string.Format("{0}/?p={1}", profileLink, i);
                    response = await CookieClient.GetHttpAsync(pageURL);

                    // Response should be empty. User should be unauthorised.
                    if (string.IsNullOrEmpty(response))
                    {
                        RetryCount++;
                        if (RetryCount == 18)
                        {
                            ResetClientStatus();
                            return;
                        }
                        throw new Exception("");
                    }
                    document.LoadHtml(response);

                    // Get all badges from current page
                    ProcessBadgesOnPage(document);
                }
            }
            catch (Exception ex)
            {
                Logger.Exception(ex, "Badge -> LoadBadgesAsync, for profile = " + Settings.Default.myProfileURL);
                // badge page didn't load
                picReadingPage.Image = null;
                picIdleStatus.Image  = null;
                lblDrops.Text        = localization.strings.badge_didnt_load.Replace("__num__", "10");
                lblIdle.Text         = "";

                // Set the form height
                var graphics = CreateGraphics();
                var scale    = graphics.DpiY * 1.625;
                Height           = Convert.ToInt32(scale);
                ssFooter.Visible = false;

                ReloadCount            = 1;
                tmrBadgeReload.Enabled = true;
                return;
            }

            RetryCount = 0;
            SortBadges(Settings.Default.sort);

            picReadingPage.Visible = false;
            UpdateStateInfo();

            if (CardsRemaining == 0)
            {
                IdleComplete();
            }
        }
Exemple #60
0
        private static Intention FormatIntention(ResumeIntention intention, string attr, string taget)
        {
            var tag      = new Intention();
            var document = new HtmlAgilityPack.HtmlDocument();

            if (string.IsNullOrWhiteSpace(intention.Salary))
            {
                tag.MinimumSalary = 0;
                tag.MinimumSalary = 0;
            }
            else if (intention.Salary.IndexOf("以上") > -1)
            {
                tag.MaximumSalary = 0;
                var match = Regex.Match(intention.Salary, "\\d*");
                if (match.Success)
                {
                    tag.MinimumSalary = Convert.ToDecimal(match.Value);
                }
            }
            else if (intention.Salary.IndexOf("以下") > -1)
            {
                tag.MinimumSalary = 0;
                var match = Regex.Match(intention.Salary, "\\d*");
                if (match.Success)
                {
                    tag.MaximumSalary = Convert.ToDecimal(match.Value);
                }
            }
            else if (intention.Salary.IndexOf('-') > -1)
            {
                tag.MinimumSalary = Convert.ToDecimal(intention.Salary.Split('-')[0]);
                var match = Regex.Match(intention.Salary.Split('-')[1], "\\d*");
                if (match.Success)
                {
                    tag.MaximumSalary = Convert.ToDecimal(match.Value);
                }
            }
            else
            {
                tag.MinimumSalary = 0;
                tag.MinimumSalary = 0;
            }

            document.LoadHtml(File.ReadAllText(Application.StartupPath + "\\XML\\Area" + taget + ".xml"));

            if (!string.IsNullOrWhiteSpace(intention.Location))
            {
                intention.Location = Regex.Replace(intention.Location, "[\\s|\\-|,|、]{1}", ",");
                foreach (var item in intention.Location.Split(','))
                {
                    if (string.IsNullOrWhiteSpace(item))
                    {
                        continue;
                    }
                    var node = document.DocumentNode.SelectSingleNode("nodes[1]/node[@" + attr + " = '" + item + "']");

                    if (node == null)
                    {
                        tag.Location += string.IsNullOrEmpty(intention.Location) ? "530000000" : ",530000000";
                    }
                    else
                    {
                        var local = string.IsNullOrEmpty(intention.Location) ? "" : node.Attributes["result-key"].Value;
                        if (!string.IsNullOrWhiteSpace(local))
                        {
                            tag.Location += "," + Convert.ToInt32(local, 16);
                        }
                    }
                }

                tag.Location = tag.Location?.Trim(',') ?? "530000000";
            }
            else
            {
                tag.Location = "530000000";
            }

            document.LoadHtml(File.ReadAllText(Application.StartupPath + "\\XML\\Industry" + taget + ".xml"));
            if (!string.IsNullOrWhiteSpace(intention.Industry))
            {
                intention.Industry = Regex.Replace(intention.Industry, "[\\s|,|、]{1}", ",");
                foreach (var item in intention.Industry.Split(','))
                {
                    if (string.IsNullOrWhiteSpace(item))
                    {
                        continue;
                    }
                    var subNode = document.DocumentNode.SelectSingleNode("nodes[1]/node[@" + attr + " = '" + item + "']");
                    if (subNode != null)
                    {
                        var sub = string.IsNullOrEmpty(intention.Industry) ? "" : subNode.Attributes["result-key"].Value;
                        if (!string.IsNullOrWhiteSpace(sub))
                        {
                            tag.Industry += "," + Convert.ToInt32(sub, 16);
                        }
                    }
                }
                tag.Industry = tag.Industry?.Trim(',') ?? "0";
            }
            else
            {
                tag.Industry = "0";
            }

            document.LoadHtml(File.ReadAllText(Application.StartupPath + "\\XML\\Function" + taget + ".xml"));
            if (!string.IsNullOrWhiteSpace(intention.Function))
            {
                intention.Function = Regex.Replace(intention.Function, "[\\s|,|、]{1}", ",");
                foreach (var item in intention.Function.Split(','))
                {
                    if (string.IsNullOrWhiteSpace(item))
                    {
                        continue;
                    }
                    var subnode = document.DocumentNode.SelectSingleNode("nodes[1]/node[@" + attr + " = '" + item + "']");
                    if (subnode == null)
                    {
                        continue;
                    }
                    var sub = string.IsNullOrEmpty(intention.Function) ? "" : subnode.Attributes["result-key"].Value;
                    if (!string.IsNullOrWhiteSpace(sub))
                    {
                        tag.Function += "," + Convert.ToInt32(sub, 16);
                    }
                }

                tag.Function = tag.Function?.Trim(',') ?? "0";
            }
            else
            {
                tag.Function = "0";
            }

            document.LoadHtml(File.ReadAllText(Application.StartupPath + "\\XML\\PresentStatus" + taget + ".xml"));

            var nodeDutyTime = document.DocumentNode.SelectSingleNode("nodes[1]/node[@" + attr + " = '" + intention.DutyTime + "']")?.Attributes["result-key"];

            if (!string.IsNullOrWhiteSpace(nodeDutyTime?.Value))
            {
                tag.DutyTime = nodeDutyTime.Value.ToCharArray().First();
            }
            else
            {
                tag.DutyTime = '*';
            }

            document.LoadHtml(File.ReadAllText(Application.StartupPath + "\\XML\\PositionType" + taget + ".xml"));
            if (!string.IsNullOrWhiteSpace(intention.JobType))
            {
                intention.JobType = Regex.Replace(intention.JobType, "[\\s|\\-|/|\\|\\\\|,|、|\\(|\\)|(|)]{1}", ",");
            }
            intention.JobType = intention.JobType.Split(',')[0] ?? "";
            var nodeJobType = document.DocumentNode.SelectSingleNode("nodes[1]/node[@" + attr + " = '" + intention.JobType + "']")?.Attributes["result-key"];

            if (!string.IsNullOrWhiteSpace(nodeJobType?.Value))
            {
                tag.JobType = nodeJobType.Value.ToCharArray().First();
            }
            else
            {
                tag.JobType = '*';
            }

            tag.Evaluation = intention.Evaluation;

            return(tag);
        }