Ejemplo n.º 1
0
        // GET: Pessoa
        public ActionResult Index()
        {
            //List<Pessoa> lista_de_Pessoas = new List<Pessoa>();
            List <Pessoa> lista_de_Estados = new List <Pessoa>();
            List <Pessoa> lista_de_Cidades = new List <Pessoa>();

            Iniciar();
            //baixar os dados do site que desejo obter as informações
            string pagina = _web.Get("gerador_de_pessoas");

            //criando uma instancia chamada documento_html
            var documento_html = new HtmlAgilityPack.HtmlDocument();

            //jogando os dados dentro do documento HTML
            documento_html.LoadHtml(pagina);

            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // coleção de dados genericos, no caso as idades do combo idade
            //validar esta perte, pois se nao tiver internet da erro
            HtmlNodeCollection nodeIdades = documento_html.GetElementById("idade").ChildNodes;

            List <string> lista_Idades = new List <string>();

            foreach (HtmlNode nodeIdade in nodeIdades)
            {
                if (nodeIdade.InnerText != "" && !nodeIdade.InnerText.Contains("\n"))
                {
                    lista_Idades.Add(nodeIdade.InnerText);
                }
            }
            ViewBag.Seleciona_Idade = new SelectList(lista_Idades);

            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // coleção de dados genericos, no caso os estados do combo estado
            HtmlNodeCollection nodeEstados = documento_html.GetElementbyId("cep_estado").ChildNodes;

            List <string> lista_Estados = new List <string>();

            //listar o nodeEstado e so add os itens se  for diferente de vazio e diferente da quebra de linha com estes espaços
            foreach (HtmlNode nodeEstado in nodeEstados)
            {
                if (nodeEstado.InnerText != "" && !nodeEstado.InnerText.Contains("\n"))
                {
                    //cmbEstadoPesquisa.Items.Add(nodeEstado.InnerText);
                    lista_Estados.Add(nodeEstado.InnerText);
                }
            }
            //ViewBag.mesmo nome que vai aparecer no HTML
            ViewBag.Estados = new SelectList(lista_Estados);

            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            var lista_cidades = new List <string>();

            lista_cidades.Add("Selecione");
            ViewBag.Cidades = new SelectList(lista_cidades);

            return(View());
        }
Ejemplo n.º 2
0
		public async Task<Rental[]> GetRentals (int page)
		{
			bool needsAuth = false;
			var rentalsUrl = ProntoRentalsUrl;
			if (page > 0)
				rentalsUrl += "/" + (page * 20);

			for (int i = 0; i < 4; i++) {
				try {
					if (needsAuth) {
						var content = new FormUrlEncodedContent (new Dictionary<string, string> {
							{ "username", credentials.Username },
							{ "password", credentials.Password }
						});
						var login = await Client.PostAsync (ProntoLoginUrl, content).ConfigureAwait (false);
						if (login.StatusCode == HttpStatusCode.Found || login.StatusCode == HttpStatusCode.OK)
							needsAuth = false;
						else
							continue;
					}

					var answer = await Client.GetStringAsync (rentalsUrl).ConfigureAwait (false);

					var doc = new HtmlDocument ();
					doc.LoadHtml (answer);
					var div = doc.GetElementById ("content");
					var table = div.Element ("table");
					return table.Element ("tbody").Elements ("tr").Select (row => {
						var items = row.Elements ("td").ToArray ();
						return new Rental {
							Id = long.Parse (items[0].InnerText.Trim ()),
							FromStationName = items [1].InnerText.Trim (),
							ToStationName = items [3].InnerText.Trim (),
							Duration = ParseRentalDuration (items [5].InnerText.Trim ()),
							Price = ParseRentalPrice (items [6].InnerText.Trim ()),
							DepartureTime = DateTime.Parse(items[2].InnerText,
							                               System.Globalization.CultureInfo.InvariantCulture),
							ArrivalTime = DateTime.Parse(items[4].InnerText,
							                             System.Globalization.CultureInfo.InvariantCulture)
						};
					}).ToArray ();
				} catch (HttpRequestException htmlException) {
					// Super hacky but oh well
					if (!needsAuth)
						needsAuth = htmlException.Message.Contains ("302");
					continue;
				} catch (Exception e) {
					e.Data ["method"] = "GetRentals";
					Xamarin.Insights.Report (e);
					Log.Error ("RentalsGenericError", e.ToString ());
					break;
				}
			}

			return null;
		}
Ejemplo n.º 3
0
        public static async Task<HtmlDocument> OpenHtmlPageAsync(string url, PortableWebClient client)
        {
            var doc = new HtmlDocument();
            LOAD_PAGE:
            doc.LoadHtml(await client.DownloadStringAsync(url));
            string title = GetTitle(doc);
            // 处理重定向。
            if (title.ToLowerInvariant().Contains("object moved"))
            {
                var nextUrl = doc.DocumentNode.Descendants("a").FirstOrDefault()?.GetAttributeValue("href", "");
                if (!string.IsNullOrEmpty(nextUrl))
                {
                    url = nextUrl;
                    goto LOAD_PAGE;
                }
                throw new UnexpectedHtmlException(url, "无法解析重定向目标。");
            }
            // 有时 CAS 中间会多一步。
            if (title.Contains("统一身份认证网关"))
            {
                var loginForm = doc.GetElementById("fm1");
                if (loginForm?.Name != "form") loginForm = null;
                if (loginForm == null)
                {
                    /*
<div id="content" class="fl-screenNavigator-scroll-container"  >
<div class="info"><p>单击 <a href="http://my.xjtu.edu.cn/Login?ticket=....">这里</a> ,便能够访问到目标应用。</p></div>
</div>
                    */
                    var node = doc.GetElementById("content");
                    var nextUrl = node?.Descendants("a").FirstOrDefault()?.GetAttributeValue("href", "");
                    if (!string.IsNullOrEmpty(nextUrl))
                    {
                        url = nextUrl;
                        goto LOAD_PAGE;
                    }
                    throw new UnexpectedHtmlException(url, "无法解析重定向目标。");
                }
            }
            return doc;
        }
Ejemplo n.º 4
0
        private async Task LoginAttemptAsync(string userName, string password)
        {
            /*
username:.....
password:.....
code:
lt:LT-.....
execution:e3s1
_eventId:submit
submit:登录
*/
            if (casAuthenticationDictBuffer == null) await UpdateCoreAsync();
            var dict = casAuthenticationDictBuffer;
            casAuthenticationDictBuffer = null;
            Debug.Assert(dict != null);
            dict["username"] = userName;
            dict["password"] = password;
            var doc = new HtmlDocument();
            using (var resp = await Client.UploadAsync(casAuthenticationUrl, dict))
                doc.LoadHtml(await resp.Content.ReadAsStringAsync());
            var node = doc.GetElementById("msg");
            if (node != null) throw new OperationFailedException(HtmlEntity.DeEntitize(node.InnerText));
            await UpdateCoreAsync();
        }
Ejemplo n.º 5
0
 //private static readonly Regex TableRegex = new Regex("<table.?*</table>", RegexOptions.Singleline);
 private static List<TrackerTopic> RutorSearch(Film film)
 {
     Uri uri = new Uri("http://rutor.org/search/0/0/300/2/" + film.InfoTable["name"][0] + " BDRemux");
     var htmlCode = Tools.GetURIContent(uri);
     var htmlDoc = new HtmlDocument();
     htmlDoc.LoadHtml(htmlCode);
     var results = htmlDoc.GetElementById("index");
     if (results.InnerText.IndexOf("Результатов поиска") == -1) return null;
     Regex searchResCount = new Regex(@"Результатов поиска \d+");
     var ResCount = searchResCount.Match(results.InnerText);
     if (!ResCount.Success) return null;
     int resultsCount = Convert.ToInt32(ResCount.Value.Substring(ResCount.Value.IndexOf("а ") + 2));
     if (resultsCount == 0)
         return new List<TrackerTopic>();
     //main part
     var magnet_tmp = "";
     var scr_tmp = "";
     var tor_file = "";
     var name_tmp = "";
     var size_tmp = "";
     int found = 0;
     var row = 1;
     List<TrackerTopic> TorFound = new List<TrackerTopic>();
     var table = results.Element("table");
     List<HtmlNode> x = table.Elements("tr").ToList();
     foreach (HtmlNode node in x)
     {
         if (node.Attributes.Contains("class") && node.Attributes["class"].Value == "backgr" ||
             row == 5)
             continue;
         List<HtmlNode> s = node.Elements("td").ToList();
         foreach (HtmlNode item in s)
         {
             switch (row)
             {
                 case 2:
                 {
                     var hrefs = item.Descendants("a").Where(t => t.Attributes.Contains("href")).ToList();
                     magnet_tmp = hrefs[0].Attributes["href"].Value;
                     scr_tmp = "http://rutor.org" + hrefs[1].Attributes["href"].Value;
                     name_tmp = item.InnerText.Replace("&nbsp;", " ").Trim();
                     break;
                 }
                 case 4:
                 case 3: //if there is no comments
                 {
                     Match szMatch = sz.Match(item.InnerText.Replace("&nbsp;", " "));
                     if (szMatch.Success)
                         size_tmp = item.InnerText.Replace("&nbsp;", " ");
                     break;
                 }
             }
             Console.WriteLine(item.InnerText.Replace("&nbsp;", " ")); //DEBUG
             row++;
         }
         if (IsCorrectFilmTorrent(name_tmp, film))
         {
             Regex rutogFilmIdRegex = new Regex(@"/torrent/[\d]+/");
             var rutorFilmIdMatch = rutogFilmIdRegex.Match(scr_tmp);
             var rutorFilmId = "";
             if (rutorFilmIdMatch.Success)
             {
                 rutorFilmId = rutorFilmIdMatch.Value.Substring("/torrent/".Length,
                     rutorFilmIdMatch.Value.Length - "/torrent/".Length - 1);
                 tor_file = "http://d.rutor.org/download/" + rutorFilmId;
                 TorFound.Add(new TrackerTopic(name_tmp, scr_tmp, tor_file, size_tmp, magnet_tmp));
                 found++;
                 scr_tmp = name_tmp = size_tmp = tor_file = magnet_tmp = "";
             }
         }
         row = 1;
         if (found >= Settings.MAX_SEARCH_RESULT)
             break;
         Console.WriteLine("-------"); //DEBUG
     }
     return TorFound;
 }
Ejemplo n.º 6
0
 private static void ParseInfoTable(string htmlCode, Film film)
 {
     var htmlDoc = new HtmlDocument();
     htmlDoc.LoadHtml(htmlCode);
     var names = htmlDoc.GetElementById("headerFilm");
     if (names == null) return;
     var _names = names.Descendants()
         .Where(t => t.Attributes.Contains("itemprop")).ToArray();
     film.InfoTable.Add("name",
         new List<string>()
         {
             MakeValueClear(_names[0].InnerText),
             MakeValueClear(_names[1].InnerText)
         });
     SetPosterInfo(film);
     var table = htmlDoc.GetElementById("infoTable");
     ClearHTMLCode(table);
     table = table.Element("table");
     string tmp = "";
     bool key = true;
     string cur_key = "";
     List<HtmlNode> x = table.Elements("tr").ToList();
     foreach (HtmlNode node in x)
     {
         List<HtmlNode> s = node.Elements("td").ToList();
         foreach (HtmlNode item in s)
         {
             tmp = MakeValueClear(item.InnerText);
             if (!String.IsNullOrWhiteSpace(tmp))
             {
                 if (key && Constants.KeyWords.ContainsKey(tmp))
                 {
                     film.InfoTable.Add(Constants.KeyWords[tmp], new List<string>());
                     cur_key = tmp;
                     key = false;
                 }
                 else
                 {
                     if (!key)
                     {
                         if (cur_key != "слоган")
                         {
                             var Arr_tmp = tmp.Split(',');
                             foreach (var i in Arr_tmp)
                             {
                                 film.InfoTable[Constants.KeyWords[cur_key]].Add(i.Trim());
                             }
                         }
                         else
                             film.InfoTable[Constants.KeyWords[cur_key]].Add(tmp);
                     }
                 }
             }
             Console.WriteLine(tmp); //DEBUG
         }
         Console.WriteLine("-------"); //DEBUG
         key = true;
     }
     //Console.ReadKey();
 }