Ex0rpl4net

Untitled

Mar 5th, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. public string scrapefunction(string url,string search, string regexstring)
  2. {
  3.  
  4. using (WebClient client = new WebClient()) // WebClient class inherits IDisposable
  5. {
  6. string allthreadusernames = "";
  7. string htmlCode = "";
  8.  
  9. while (String.IsNullOrEmpty(htmlCode))
  10. {
  11. try
  12. {
  13. htmlCode = client.DownloadString(url);
  14. }
  15. catch
  16. {
  17. }
  18. }
  19. string[] htmlarray = htmlCode.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
  20. foreach (string line in htmlarray)
  21. {
  22. if (line.Contains(search))
  23. {
  24.  
  25. var regex = new Regex(regexstring);
  26. var matches = regex.Matches(line);
  27. foreach (var singleuser in matches.Cast<Match>().ToList())
  28. {
  29. allthreadusernames = allthreadusernames + "\n" + singleuser.Groups[1].Value;
  30.  
  31.  
  32. }
  33. }
  34. }
  35.  
  36. return allthreadusernames;
  37.  
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment