Parsing Pages with XPath in BAS
The XPath module in Browser Automation Studio — extract elements and text from HTML and XML quickly, the backbone of most scrapers and parsers built in BAS.
When a bot needs to pull data out of a page, the tool of choice in BAS is XPath. It’s one of the most-used modules in the whole product, because parsing is at the heart of so many bots — and XPath is the fastest way to do it.
What XPath is
XPath is a query language for HTML and XML pages. You write an expression that points at the part of the document you want, and XPath returns it. It’s purpose-built for parsing: instead of hunting through raw HTML, you address elements directly and pull their contents.
The actions
- XPath get HTML — return the HTML of the matched element.
- XPath get each HTML — return the HTML of every matched element, for looping over a set.
- XPath get text — return the text content of the matched element.
- XPath get each text — return the text of every match, ideal for a list of rows.
- XPath get attribute — read an attribute such as
hreforsrc. - XPath check existence — test whether a match exists, so you can branch when a field is missing.
A concrete example
Building a classifieds parser — an Avito-style scraper — is the classic case. You open the listings in a browser, then for each product card you use XPath to pull the characteristics, description and photo. XPath get each text walks the cards, XPath get attribute grabs image URLs, and XPath check existence keeps the flow alive when a card is missing a field.
XPath in the parsing toolkit
XPath is for rendered HTML/XML — the page as the browser sees it. It pairs naturally with the rest of the data toolkit: locate and click elements with selectors, parse API responses with JSON, and clean the extracted text with string operations. For most scraping jobs, though, XPath is where the real extraction happens — learn it well and parsing stops being the hard part.
FAQ
What is XPath used for in BAS?
XPath is a query language for HTML and XML pages. In BAS it is one of the most-used modules for parsing — quickly extracting elements and their text from a page, such as a product card title, description and photo on a classifieds site.
How do I build an Avito-style parser in BAS?
Open the listings in a browser, then use the XPath module to pull each card field — title, description, price, photo. XPath get text and XPath get html return the data; XPath check existence guards against missing fields.
- Browser Automation Studio: The Complete Practical GuideGuide
- Building Your First Bot in Browser Automation StudioA step-by-step walkthrough of creating your first working BAS bot — from a blank project to a flow that navigates, extracts data, and runs in multiple threads.
- Setting Up Proxies in Browser Automation StudioHow to configure proxies in BAS the right way — proxy types, per-thread assignment, rotation, and the checks that keep multi-account bots from getting flagged.
- Finding Elements in BAS: Selectors That Don't BreakHow element search works in Browser Automation Studio — CSS vs XPath selectors, why recorded ones break, and how to write selectors that survive page changes.