.NET 4.x Распарсить HTML страницу для получения теста между тегами - C#
Формулировка задачи:
Собственно проблема заключается в том что не получается спарсить текст между тэгов, пробовал все возможные способы.
Есть html код:
Нужно вытащить "Crunchyroll (1)"(динамическое).
Пробовал с помощью регулярки:
string match = Regex.Match(text, "itemTitle-0\" class=\"grayBoxFormPadding\">(.*)<label").ToString();
В итоге match пустой...
И ещё, пробелы в исходном коде страницы какие-то не стандартные, я их пробовал убирать с помощью replace, они то убирались, но спарсить всё равно не выходило..
Прошу помощи.
<section class="formValue">
<div id="itemTitle-0" class="grayBoxFormPadding">
Crunchyroll (1)
<label id="selLabelOrderAmount_0">$0.00</label>
</div>
</section>
<div class="clearMe"></div>
Решение задачи: «.NET 4.x Распарсить HTML страницу для получения теста между тегами»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
class Program
{
static void Main(string[] args)
{
string html = "<section class=\"formValue\">" +
"<div id=\"itemTitle-0\" class=\"grayBoxFormPadding\">" +
"Crunchyroll (1)" +
"<label id=\"selLabelOrderAmount_0\">$0.00</label>" +
"</div>" +
"</section>" +
"<div class=\"clearMe\"></div>";
string str1 = "<div id=\"itemTitle-0\" class=\"grayBoxFormPadding\">";
string str2 = "<label";
int input1 = html.IndexOf(str1);
int input2 = html.IndexOf(str2, input1);
string match = html.Substring(input1 + str1.Length, input2 - (input1 + str1.Length));
Console.WriteLine(match);
Console.ReadKey();
}
}