private void ToList(HtmlElementCollection collection, List <String> list) { System.Collections.IEnumerator it = collection.GetEnumerator(); while (it.MoveNext()) { HtmlElement htmlElement = (HtmlElement)it.Current; list.Add(htmlElement.OuterHtml); } }
private void download_Click(object sender, EventArgs e) { WebClient client = new WebClient(); try { HtmlElement download_link = downloadBrowser.Document.GetElementById("dl_link"); HtmlElementCollection links = download_link.GetElementsByTagName("a"); System.Collections.IEnumerator nums = links.GetEnumerator(); String link = ""; while (nums.MoveNext()) { HtmlElement hold = (HtmlElement)nums.Current; if (hold.GetAttribute("href").Contains("?ab=")) { link = hold.GetAttribute("href"); } } /* * for (int i = 0; i < 4; i++) * { * if (links[i].GetAttribute("href").Contains("?ab")) * { * link = links[i].GetAttribute("href"); * } * else * { * label1.Text = "unable to find link"; * } * } */ youtube_url.Text = link; downloadBrowser.Navigate(link); client.DownloadFileAsync(new Uri(link), "test.mp3"); //youtube_url.Text = link; //System.Diagnostics.Process.Start(link); //MessageBox.Show("downloaded file"); } catch (Exception) { MessageBox.Show("Unable to download file"); } }
void groupsGeter_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { if (e.Url != groupsGeter.Url) { return; } listBox1.Items.Clear(); HtmlElementCollection elementsByTagName = groupsGeter.Document.GetElementsByTagName("a"); var sequenceEnum = elementsByTagName.GetEnumerator(); while (sequenceEnum.MoveNext()) { HtmlElement current = (HtmlElement)sequenceEnum.Current; if (!current.GetAttribute("href").Contains("/groups/")) { continue; } if (current.GetAttribute("href").Contains("/create/")) { continue; } if (current.GetAttribute("href").Contains("category")) { continue; } if (current.GetAttribute("href").Contains("?see")) { continue; } string item = current.GetAttribute("href").ToString(); if (listBox1.Items.Contains(item)) { continue; } listBox1.Items.Add(item); } totalGPS.Text = listBox1.Items.Count.ToString(); }
public static List <HtmlElement> ChgHtmlColToListJSCD(HtmlElementCollection htmlCollection) { List <HtmlElement> elementList = new List <HtmlElement>(); try { if (htmlCollection != null) { IEnumerator itrator = htmlCollection.GetEnumerator(); HtmlElement curElement = null; while (itrator.MoveNext()) { curElement = (HtmlElement)itrator.Current; elementList.Add(curElement); } } } catch (Exception ex) { throw ex; } return(elementList); }
void groupsJoinerGet_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { if (e.Url != groupsJoinerGet.Url) { return; } try { if (listBox2.Items.Count >= int.Parse(lim.Text)) { WriteLine("Groups search is done!"); currnav = loop + 1;// to end all return; } HtmlElementCollection elementsByTagName = groupsJoinerGet.Document.GetElementsByTagName("a"); var sequenceEnum = elementsByTagName.GetEnumerator(); while (sequenceEnum.MoveNext()) { HtmlElement current = (HtmlElement)sequenceEnum.Current; if (!current.GetAttribute("href").Contains("/groups/")) { continue; } if (current.GetAttribute("href").Contains("/search/")) { continue; } if (current.GetAttribute("href").Contains("/create/")) { continue; } if (current.GetAttribute("href").Contains("category")) { continue; } if (current.GetAttribute("href").Contains("?see")) { continue; } string item = current.GetAttribute("href").ToString(); uint members = 0; Uri ur = new Uri(item); foreach (HtmlElement epp in groupsJoinerGet.Document.All) { if (epp.InnerText == null) { continue; } if (epp.InnerText.Contains(current.InnerText)) { string[] p = epp.InnerText.Split(new string[] { "\r\n" }, StringSplitOptions.None); if (p.Length == 2) { try { members = uint.Parse(p[1].Replace(",", "").Replace("Members", "")); break; } catch { MessageBox.Show("Error : " + p[0] + " __________ " + p[1]); continue; } } } } AddNwGp(current.InnerText, ur.AbsolutePath.Replace("/groups/", "").Replace("/", ""), members); } if (currnav <= loop) { currnav++; beg += 5; if (keyword.Text != "") { this.groupsJoinerGet.Navigate("https://m.facebook.com/search/?query=" + keyword.Text + "&search=group&pn=" + currnav + "&ssid=0&s=" + beg);//+ "&tsid&o=69&refid=46"); } else { MessageBox.Show("Invalid keyword"); currnav = loop + 1;// to end all } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }