Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- namespace ConsoleApplication17 {
- class Program {
- const string url = "http://www.phonearena.com";
- const string mainurl = "http://www.phonearena.com/phones/manufacturers";
- const string fileName = "phones.txt";
- static void Main (string[] args) {
- System.IO.File.WriteAllText(fileName,"");
- foreach(String m in applyRegex(@"(?<=<a href="")\/phones\/manufacturers.*(?="" class)",getSource(mainurl))){
- int number = 1;
- Console.Write(number + " ");
- System.IO.File.AppendAllText(fileName,m.Split('/')[m.Split('/').ToList<string>().Count-1] + ":" + Environment.NewLine);
- string source = getSource(url+m);
- int maxPg = Convert.ToInt32(applyRegex(@"(?<=onclick='changePage\().?\d(?=, this.href)",source)[applyRegex(@"(?<=onclick='changePage\().?\d(?=, this.href)",source).Count-1]);
- string regexPhone = @"(?<=alt="").*?(?="" widht=""150"")";
- foreach(String s in applyRegex(regexPhone,source))
- System.IO.File.AppendAllText(fileName,s+" ");
- Console.Write(maxPg + ": ");
- for(int i = 2;i<=maxPg;i++) {
- Console.Write(i+" ");
- foreach(String s in applyRegex(regexPhone,getSource(url+m+"/page/"+i+"/")))
- System.IO.File.AppendAllText(fileName,s+" ");
- }
- System.IO.File.AppendAllText(fileName,Environment.NewLine);
- Console.Clear();
- number++;
- }
- }
- public static string getSource (string url) {
- using(WebClient client = new WebClient()) {
- return client.DownloadString(url);
- }
- }
- public static List<string> applyRegex (string regex,string sourcestring) {
- Regex re = new Regex(regex);
- return re.Matches(sourcestring).Cast<Match>().Select(mm => mm.Value).Skip(1).Distinct().ToList<string>();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement