I make a regex pattern and tested in this site : http://rubular.com/
I'm writing this pattern exactly like this to the first box in that site.
<div class="product clearfix">\n+<div class="img">\n+<a href="(.*?)">\n+<img class="lazyload" id='.*' data-original="(.*?)" alt=".*" title="(.*?)" \/>
I left the second box empty.
My regex pattern working perfectly fine respect to this site.
But i can't get it working in C#
I'm trying this:
WebClient client = new WebClient();
string MainPage = client.DownloadString("http://www.vatanbilgisayar.com/cep-telefonu-modelleri/");
string ItemPattern = "<div class=\"product clearfix\">\\n+" + // <div class="product clearfix">\n
"<div class=\"img\">\\n" + // <div class="img">\n
"+<a href=\"(.*?)\">\\n" + // +<a href="(.*?)">\n
"+<img class=\"lazyload\"" + // +<img class="lazyload"
"id='.*' data-original=\"(.*?)\"" + // id='.*' data-original="(.*?)"
"alt=\".*\" title=\"(.*?)\"\\/>"; // alt=".*" title="(.*?)" \/>
MatchCollection matches = Regex.Matches(MainPage, ItemPattern);
foreach (Match match in matches)
{
Console.WriteLine("Area Code: {0}", match.Groups[1].Value);
Console.WriteLine("Telephone number: {0}", match.Groups[2].Value);
Console.WriteLine();
}
I simply escaped every " with \ . I really don't understand why it's not working and this starting to drive me crazy..