Python Scrapy: Extracting Quotes and Authors

To extract the quotes from the webpage, observe how they are represented in HTML on the webpage:

<div class="quote">
    <span class="text">“Quote here”</span>
    <span>
        by <small class="author">Author Name</small>
        <a href="/author/Author-Name">(about)</a>
    </span>
    <div class="tags">
        Tags:
        <a class="tag" href="/tag/tag-name/page/1/">tag-name</a>
    </div>
</div>

Using the Scrapy shell, you can extract the text, author, and tags:

quote = response.css("div.quote")[0]
text = quote.css("span.text::text").get()
author = quote.css("small.author::text").get()
tags = quote.css("div.tags a.tag::text").getall()

Previous     Next

Use the Search Bar to find content on MarketingMind.