使用CSS Selector从网页中选择CSS元素时遇到问题

时间:2017-08-23 11:34:06

标签: c# html css css-selectors

目前我一直在使用CsQuery进行网页编写。

我现在遇到的问题是让实际正确的CSS Selector找到HTML代码中的元素。

所以在我的网页上,这是我试图通过

解析的部分
<div id="workskin">
<div class="preface group">
    <h2 class="title heading">
        Pocket Healer
        </h2>
    <h3 class="byline heading">
        <a rel="author" href="/users/OverNoot/pseuds/OverNoot">OverNoot</a>
    </h3>
    <div class="summary module" role="complementary">
        <h3 class="heading">Summary:</h3>
        <blockquote class="userstuff">
            <p>
                "summary text goes here"
            </p>
        </blockquote>
    </div>

    <!-- Nothing else of importance past this point -->

在我的代码中,我尝试突出显示重要的部分,但它似乎并没有起作用

    //Takes in URL from message
    //Loads up Ao3 page and parses for Title, Author, and Summary
    public String searchFanfic(String url)
    {
        String responseString = "```"; //Formatted message for discord bot to send to the channel

        CQ dom = CQ.CreateFromUrl(url);
        CQ workskin = dom.Select("#workskin");

        var title = workskin.Find("h2.tile.heading").Text();

        var summary = workskin.Find("blockquote.userstuff").Text();

        var author = workskin.Find("h3.heading a[rel=author]").Text();

        responseString +=
            "Title: " + title +
            "\nAuthor: " + author +
            "\nsummary: " + summary;

        responseString += "```";
        return responseString;
    }

0 个答案:

没有答案