0

I want to catch some data from a website using HtmlAgilityPack. The data is stored in an object with the property class="addresscolor__". But the problem is that there is more than one class with this name. And I want to know is there any way to get this data from a specific class with that value, using "Start with" or "Contained.." or some thing like this ?

HTML Code :

<p class="addresscolor__">
    <span>Phone:</span>
    33875362 ، 22356341
    <br />
</p>

<p class="addresscolor__">
    <span>mobile:</span>
    09125231827
    <br />
</p>

I use thhis code:

HtmlNodeCollection nodes2 = doc.DocumentNode.SelectNodes("//p[@class='addresscolor__']");

The other thing is, that this class contained span tag and with these codes I catch the whole <p> tag values, but I want a number only in "Mobile" span tag.

Marco
  • 22,856
  • 9
  • 75
  • 124
M.Tajari
  • 59
  • 11

1 Answers1

1

For finding this paragraph:

//p[@class='addresscolor__' and contains(span, 'mobile:')]

For limiting to its text node (the phone number):

//p[@class='addresscolor__' and contains(span, 'mobile:')]/text()

For further stripping whitespace:

normalize-space(//p[@class='addresscolor__' and contains(span, 'mobile:')]/text())

For matching HTML classes, also consider a node can have multiple classes and how to deal with that.

Community
  • 1
  • 1
Jens Erat
  • 37,523
  • 16
  • 80
  • 96