PINGDOM_CHECK

#ExtractSummit2026 The world's largest web scraping conference returns. Austin Oct 7–8 · Dublin Nov 10–11.

Register now
Data Services
Pricing
Login
Try Zyte APIContact Sales
  • Unblocking and Extraction

    Zyte API

    The ultimate API for web scraping. Avoid website bans and access a headless browser or AI Parsing

    Ban Handling

    Headless Browser

    AI Extraction

    SERP

    Enterprise

    DocumentationSupport

    Hosting and Deployment

    Scrapy Cloud

    Run, monitor, and control your Scrapy spiders however you want to.

    Coding Agent Add-Ons

    Agentic Web Data

    Plugins that give coding agents the context to build production Scrapy projects. Starts with Claude Code.

  • Data Services
  • Pricing
  • Browse

    • BlogArticles, podcasts, videos
    • Case studiesCustomer outcomes
    • White papersIn-depth reports
    • EventsConferences, webinars, recordings

    Subscribe

    • NewsletterSwiftly delivered
    • Discord communityExtract Data community
  • Product and E-commerce

    From e-commerce and online marketplaces

    Data for AI

    Collect and structure web data to feed AI

    Job Posting

    From job boards and recruitment websites

    Real Estate

    From Listings portals and specialist websites

    News and Article

    From online publishers and news websites

    Search

    Search engine results page data (SERP)

    Social Media

    From social media platforms online

  • Meet Zyte

    Our story, people and values

    Contact us

    Get in touch

    Support

    Knowledge base and raise support tickets

    Terms and Policies

    Accept our terms and policies

    Open Source

    Our open source projects and contributions

    Web Data Compliance

    Guidelines and resources for compliant web data collection

    Join the team building the future of web data
    We're Hiring
    Trust Center
    Security, compliance & certifications
Login
Try Zyte APIContact Sales

Zyte Developers

Coding tools & hacks straight to your inbox

Become part of the community and receive a bi-weekly dosage of all things code.

Join us
    • Zyte Data
    • News & Articles
    • Search
    • Social Media
    • Product
    • Data for AI
    • Job Posting
    • Real Estate
    • Zyte API - Ban Handling
    • Zyte API - Headless Browser
    • Zyte API - AI Extraction
    • Web Scraping Copilot
    • Zyte API Enterprise
    • Scrapy Cloud
    • Solution Overview
    • Blog
    • Webinars
    • Case Studies
    • White Papers
    • Documentation
    • Web Scraping Maturity Self-Assesment
    • Web Data compliance
    • Meet Zyte
    • Jobs
    • Terms and Policies
    • Trust Center
    • Support
    • Contact us
    • Pricing
    • Do not sell
    • Cookie settings
    • Sign up
    • Talk to us
    • Cost estimator
All articles
AI60, 60 articles
Data quality13, 13 articles
Developer interest57, 57 articles
Integration2, 2 articles
Open-source40, 40 articles
Proxies29, 29 articles
Scraping practice17, 17 articles
Scraping strategy26, 26 articles
Web data60, 60 articles
Web scraping APIs33, 33 articles
Zyte API59, 59 articles
Scrapy48, 48 articles
Scrapy Cloud10, 10 articles
Web Scraping Copilot12, 12 articles
AI & Machine Learning1, 1 articles
Automotive2, 2 articles
E-commerce & retail26, 26 articles
Entertainment & Streaming2, 2 articles
Financial Services8, 8 articles
Government2, 2 articles
Market Research & Intelligence3, 3 articles
Media & publishing8, 8 articles
Real Estate2, 2 articles
Recruitment & HR3, 3 articles
Transportation & Logistics2, 2 articles
Travel & hospitality2, 2 articles
Extract Summit25, 25 articles
PyCon1, 1 articles

Appearance

Discord Community
BlogOpen-sourceMeet Parsel: The Selector Library Behind Scrapy
ArticleOpen-source

Meet Parsel: The Selector Library Behind Scrapy

We eat our own spider food since Scrapy is our go-to workhorse on a daily basis. However, there are certain situations where Scrapy can be overkill and that’s

V

Valdir Stumm Junior

3 min read · July 28, 2016

Meet Parsel: The Selector Library Behind Scrapy

Meet Parsel: The selector library behind Scrapy

We eat our own spider food since Scrapy is our go-to workhorse on a daily basis. However, there are certain situations where Scrapy can be overkill and that’s when we use Parsel. Parsel is a Python library for extracting data from XML/HTML text using CSS or XPath selectors. It powers the scraping API of the Scrapy framework.

HarryParseltongue

We extracted Parsel from Scrapy during Europython 2015 as a part of porting Scrapy to Python 3. As a library, it’s lighter than Scrapy (it relies on lxml and cssselect) and also more flexible, allowing you to use it within any Python program.

Using Parsel

Install Parsel using pip:

1pip install parsel
Copy

And here’s how you use it. Say you have this HTML snippet in a variable:

Plain text

Copy to clipboard

Open code in new window

EnlighterJS 3 Syntax Highlighter

>>> html = u'''

  • Blog
  • ...
  • Scrapinghub
  • ...
  • Scrapy
'''

>>> html = u'''

  • Blog
  • ...
  • Scrapinghub
  • ...
  • Scrapy
'''

1\>>> html = u''' <ul> <li><a href="http://blog.scrapinghub.com">Blog</a></li> ... <li><a href="https://www.scrapinghub.com">Scrapinghub</a></li> ... <li class="external"><a href="http://www.scrapy.org">Scrapy</a></li> </ul> '''
Copy

You then import the Parsel library, load it into a Parsel Selector and extract links with an XPath expression:

Plain text

Copy to clipboard

Open code in new window

EnlighterJS 3 Syntax Highlighter

>>> import parsel >>> sel = parsel.Selector(html) >>> sel.xpath("//a/@href").extract() [u'http://blog.scrapinghub.com', u'https://www.scrapinghub.com', u'http://www.scrapy.org'\]

>>> import parsel >>> sel = parsel.Selector(html) >>> sel.xpath("//a/@href").extract() [u'http://blog.scrapinghub.com', u'https://www.scrapinghub.com', u'http://www.scrapy.org'\]

1\>>> import parsel >>> sel = parsel.Selector(html) >>> sel.xpath("//a/@href").extract() \[u'http://blog.scrapinghub.com', u'https://www.scrapinghub.com', u'http://www.scrapy.org'\]
Copy

Note: Parsel works both in Python 3 and Python 2. If you’re using Python 2, remember to pass the HTML in a unicode object.

Sweet Parsel Features

One of the nicest features of Parsel is the ability to chain selectors. This allows you to chain CSS and XPath selectors however you wish, such as in this example:

Plain text

Copy to clipboard

Open code in new window

EnlighterJS 3 Syntax Highlighter

>>> sel.css('li.external').xpath('./a/@href').extract() [u'http://www.scrapy.org'\]

>>> sel.css('li.external').xpath('./a/@href').extract() [u'http://www.scrapy.org'\]

1\>>> sel.css('li.external').xpath('./a/@href').extract() \[u'http://www.scrapy.org'\]
Copy

You can also iterate through the results of the .css() and .xpath() methods since each element will be another selector:

Plain text

Copy to clipboard

Open code in new window

EnlighterJS 3 Syntax Highlighter

>>> for li in sel.css('ul li'): ... print(li.xpath('./a/@href').extract_first()) ... http://blog.scrapinghub.com https://www.scrapinghub.com http://www.scrapy.org

>>> for li in sel.css('ul li'): ... print(li.xpath('./a/@href').extract_first()) ... http://blog.scrapinghub.com https://www.scrapinghub.com http://www.scrapy.org

1\>>> for li in sel.css('ul li'): ... print(li.xpath('./a/@href').extract\_first()) ... http://blog.scrapinghub.com https://www.scrapinghub.com http://www.scrapy.org
Copy

You can find more examples of this in the documentation.

When to use Parsel

The beauty of Parsel is in its wide applicability. It is useful for a range of situations including:

  • Processing XML/HTML data in an IPython notebook
  • Writing end-to-end tests for your website or app
  • Simple web scraping projects with the Python Requests library
  • Simple automation tasks at the command-line

And now, you can also run Parsel with the command-line tool for simple extraction tasks in your terminal. This new development is thanks to our very own Rolando who created parsel-cli.

Install parsel-cli with pip install parsel-cli and play around using the examples below (you need to have curl installed).

The following command will download and extract the list of Academy Award-winning films from Wikipedia:

Plain text

Copy to clipboard

Open code in new window

EnlighterJS 3 Syntax Highlighter

curl -s https://en.wikipedia.org/wiki/List\_of\_Academy\_Award-winning\_films | parsel-cli 'table.wikitable tr td i a::text'

curl -s https://en.wikipedia.org/wiki/List\_of\_Academy\_Award-winning\_films | parsel-cli 'table.wikitable tr td i a::text'

1curl -s https://en.wikipedia.org/wiki/List\_of\_Academy\_Award-winning\_films | parsel-cli 'table.wikitable tr td i a::text'
Copy

You can also get the current top 5 news items from Hacker News using:

Plain text

Copy to clipboard

Open code in new window

EnlighterJS 3 Syntax Highlighter

curl -s https://news.ycombinator.com |

parsel-cli 'a.storylink::attr(href)' | head -n 5

curl -s https://news.ycombinator.com | parsel-cli 'a.storylink::attr(href)' | head -n 5

1curl -s https://news.ycombinator.com |
2 parsel-cli 'a.storylink::attr(href)' | head -n 5
Copy

And how about obtaining a list of the latest YouTube videos from a specific channel?

Plain text

Copy to clipboard

Open code in new window

EnlighterJS 3 Syntax Highlighter

curl -s https://www.youtube.com/user/crashcourse/videos |

parsel-cli 'h3 a::attr(href), h3 a::text' |

paste -s -d' n' - | sed 's|^|http://youtube.com|'

curl -s https://www.youtube.com/user/crashcourse/videos | parsel-cli 'h3 a::attr(href), h3 a::text' | paste -s -d' n' - | sed 's|^|http://youtube.com|'

1curl -s https://www.youtube.com/user/crashcourse/videos |
2 parsel-cli 'h3 a::attr(href), h3 a::text' |
3 paste -s -d' n' - | sed 's|^|http://youtube.com|'
Copy

Wrap Up

I hope that you enjoyed this little tour of Parsel and I am looking forward to seeing how these examples have sparked your imagination when finding solutions for your HTML parsing needs.

The next time you find yourself wanting to extract data from HTML/XML and don’t need Scrapy and its crawling capabilities, you know what to do: just Parsel it!

Feel free to reach out to us on Twitter and let us know how you use Parsel in your projects.

Try Zyte API

Build your first scraper in minutes

Free trial, no credit card. From a single request to production in an afternoon.

Get started
Open-source
V

Valdir Stumm Junior

More from this author

In this article

  • Using Parsel
  • Sweet Parsel Features
  • When to use Parsel
  • Wrap Up

Follow

Get the latest

Zyte and the data web in your inbox — or wherever you already are.

Subscribe

Or follow elsewhere

Continue reading

Scrapy in 2026: New release brings modern async crawling standards
Open Source

Scrapy in 2026: New release brings modern async crawling standards

Scrapy 2.14.0 is released with a major under-the-hood modernization. Say goodbye to Twisted Deferreds.

Robert Andrews·6 min·January 12, 2026
The new economics of web data: Smaller scraping just got cheaper
Open Source

The new economics of web data: Smaller scraping just got cheaper

Smarter tools and AI-driven automation are rewriting the rules of web scraping. As costs fall and setup barriers vanish, smaller teams can now compete at scale, reshaping how the web’s data economy works.

Theresia Tanzil·2 mins·October 6, 2025
A Deep Dive into Zyte's Open-Source Libraries
Open Source

A Deep Dive into Zyte's Open-Source Libraries

Discover how Zyte’s open-source libraries like ClearHTML, Extruct, Chomp.js, and more simplify web data extraction and processing.

Neha Setia Nagpal·1 mins·December 19, 2024

The Community · Newsletter

The best of Zyte and the data web, in your inbox.

One curated edition — new articles, product updates, and the stories shaping the data web. No noise.

G2.com

Capterra.com

Proxyway.com

EWDCI logoMost loved workplace certificateZyte rewardISO 27001 iconG2 rewardG2 rewardG2 reward

© Zyte Group Limited 2026