0

I want to catch some info from a webpage using html agility pack. But the info that I want to use is like this :

Exp1: 22391021 - 09198606027 - 88345027

Exp2: 22252554 - 29458456 - 09365861449

Exp3: chiako.com 09123937651 - 88424554 (4 Line)

And input it to the some parameters with foreach method.

How can I only catch mobile phone with this structure ( 09xxxxxxxxx ) ? Like below examples:

1- 09198606027

2- 09365861449

3- 09123937651

And put it into the parameter(s).

My code:

public void GetingInformarion()
{
    string PageLoad = "http://rahnama.com/cat/index/id/38093/%D8%A7%D8%B9%D8%B2%D8%A7%D9%85-%D8%AF%D8%A7%D9%86%D8%B4%D8%AC%D9%88";
    HtmlWeb hw = new HtmlWeb();
    HtmlAgilityPack.HtmlDocument doc = hw.Load(PageLoad);
    HtmlNodeCollection nodes1 = doc.DocumentNode.SelectNodes("//p[@style='margin:0;']/span");
    foreach (HtmlNode node in nodes1)
    {
        string Name = node.InnerText;
    }
}
Alexander
  • 4,153
  • 1
  • 24
  • 37
M.Tajari
  • 59
  • 11

2 Answers2

3

Try to match your string with regular expression:

var match = Regex.Match(node.InnerText, @"09\d{9}");
if (match.Success)
{
  string Name = match.Value; // your matched phone number
}

If you expect several phone numbers in string, you can use NextMatch method:

while (match.Success) 
{
     string Name = match.Value;
     match = match.NextMatch();
}
Alexander
  • 4,153
  • 1
  • 24
  • 37
0

You can use Regex to find all the matches with a particular pattern. Please take a look at: regular expression for Indian mobile numbers for relevant regex for mobile number.

Community
  • 1
  • 1
Siva Gopal
  • 3,474
  • 1
  • 25
  • 22