来自javascript文字的信息?

时间:2011-08-12 20:37:33

标签: c#

我试图从网站(http://wowhead.com)获取一些信息,如果它很容易使用html敏捷包,但我坚持如何在java脚本标记后获取信息。

我试图从中获取信息的来源是

<script type="text/javascript">//<![CDATA[
Markup.printHtml("[ul][li]Level: 49[/li][li]Requires level 47[/li][li]Loremaster:         [url=/achievement=4931]Felwood[/url][/li][li]Side: [span class=icon-horde]Horde[/span][/li]    [li][icon name=quest_start]Start: [url=/npc=48127]Darla Drilldozer[/url][/icon][/li][li]    [icon name=quest_end]End: [url=/npc=48127]Darla Drilldozer[/url][/icon][/li]    [li]Sharable[/li][li]Difficulty: [color=r2]47[/color][small] &nbsp;[/small][color=r3]52[/color][small] &nbsp;[/small][color=r4]59[/color][/li][li]Added in patch 4.0.3[/li][/ul]", "sdhafcuvh0", { allow: Markup.CLASS_STAFF, dbpage: true });
//]]></script> 

现在,所有这一切,我唯一感兴趣的是来自

的信息
[url=/npc=48127]Darla Drilldozer[/url]

我只想从中显示48127和Darla Drilldozer。

有没有这样做?

以下是我在控制台中显示当前代码的示例,以显示

之后的内容
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;
using HtmlAgilityPack;

namespace ConsoleApplication1
{
class Program
{
    static void Main(string[] args)
    {
        //Enter the Quest ID and set it as a WoWHead link
        Console.WriteLine("Enter quest ID");
        string ID = Console.ReadLine();
        Console.WriteLine("Gathering Quest information from: http://www.wowhead.com/quest=" + ID);

        //Load WoWHead and search for the quest name in <h1>
        HtmlWeb web = new HtmlWeb();
        HtmlDocument doc = web.Load("http://wowhead.com/quest=" + ID);
        HtmlNodeCollection Qname = doc.DocumentNode.SelectNodes("//h1");

        //Set QuestName as the second <h1> tag
        string QuestName = (Qname[1].InnerText);

        //Display information recivied
        Console.WriteLine("Quest ID: " + ID);
        Console.WriteLine("Quest Name: " + QuestName);
        Console.WriteLine("Quest Giver: " );
        Console.WriteLine("Quest Giver ID: ");
        Console.ReadLine();
    }
}

}

所以Quest giver和Quest giver ID所需的信息来自上面的Javascript。

有没有办法获取这些信息?

1 个答案:

答案 0 :(得分:0)

有许多方法可以对猫进行换肤,在这种情况下,其中一种方法是找到您要查找的单词的位置并使用简单的string.substring。那会对你有用吗?