Counting class on the Site (source code)

Kacmil

Новичок
Регистрация
22.12.2016
Сообщения
23
Благодарностей
1
Баллы
3
Hi everyone,
I have a problem with counting class on the site in source code.
For example I have on the site that line:
<a class="seo-link" href="examplesite.com">Anchor</a>
I don't know how I may counting quantity of class "seo-link".

If the site will be two such classes I got result in variable = 2,
when will be three classess I got result in variable=3 etc.

Can you give an example of how to solve that?
 

Ribas

Client
Регистрация
31.05.2014
Сообщения
1 377
Благодарностей
464
Баллы
83
parse DOM with regex <a\ class="seo-link" - get all matches in the list, after that get number of rows in the list
 
  • Спасибо
Реакции: Kacmil

Kacmil

Новичок
Регистрация
22.12.2016
Сообщения
23
Благодарностей
1
Баллы
3
I would request, could you show me an example? I made take DOM but didn't work.
I'm just a beginner, so sorry for the large number of questions.
upload_2017-1-4_7-34-41.png
 

amyboose

Client
Регистрация
21.04.2016
Сообщения
2 312
Благодарностей
1 191
Баллы
113
Код:
project.Variables["count"].Value = (project.Variables["test"].Value.Split(new[] { @"<a class=""seo-link"" href=""examplesite.com"">Anchor</a>" }, StringSplitOptions.None).Length - 1).ToString();
 
  • Спасибо
Реакции: Kacmil

Kacmil

Новичок
Регистрация
22.12.2016
Сообщения
23
Благодарностей
1
Баллы
3
Thank you for help. I have one more question.
I have a page with many articles. I would like to copy 5 words to variable with each article in proper Div.

For example:
<div class=box>
<p>
Something was making strange noises. There was something inside the cupboard. “Oh no! What is it?” Amy was very frightened now
</p>
</div>

Every time I would like to get three words (dot) two words. Like above.
 

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)