Парсинг HTML регулярными выражениями
Решил написать дампер Сториса (портал с рассказами)
На странице рассказа вот так:
<h1 id="story_title">{ИМЯРАССКАЗА}
<span class="vote">
Код таков:
storyid++;
listBox1.Items.Add("Checking story: " + storyid + "..");
currStoryHTML = getHTML("http://site/story/" + storyid);
if (currStoryHTML == "404NOTFOUND") return;
Match match = Regex.Match(currStoryHTML, @"(?<=<<h1 id=" + "\"" + "story_title" + "\"" + ">>)(.*)(?=<span class=" + "\"" + "vote" + "\"" + ">)");
if (match.Success)
{
listBox1.Items.Add("Story with ID: " + storyid + " have name: " + match);
}
else
{
listBox1.Items.Add("Story with ID: " + storyid + " do not have name OR invalid..");
return;
}
Не важно, существует ли рассказ. Всегда math.Success = false Поможете?
Источник: Stack Overflow на русском