This module has only been tested on https://willhaben.at
!
There are two ways you can use this API. Either by entering the URL and let the API extract all the results or by using the builder to build the URL and let the API extract the results.
For this method you need an URL of the willhaben search you want to make. Then you use the .getListings(URL) function and it returns a promise which resolves to an array with all the results.
This example searches for rtx
in the Grafikkarten
category and will show the first 1000 results.
const willhaben = require('willhaben')
willhaben.getListings('https://www.willhaben.at/iad/kaufen-und-verkaufen/marktplatz/pc-komponenten/-5882?keyword=rtx&rows=100').then(json => {
console.log(json)
})
The URL builder is obtainable with the .new()
function. Then you can use various methods on the object and execute the search with .search()
. This method returns a promise which resolves to an array containing all the results.
Available methods in the builder:
Method | Description |
---|---|
.category(string) | sets the category id to search (default: all) |
.condition(int) | adds a condition to search |
.transferType(int) | adds a transfer type to search |
.count(int) | sets the count of how many results should be searched for |
.paylivery(boolean) | sets if you should search for PayLivery |
.keyword(string) | sets the keyword to search for (basically a text search) |
.periode(int) | sets the periode, in days, in which to search for |
.priceFrom(int) | sets the minimum price to search for |
.priceTo(int) | sets the maximum price to search for |
.sortBy(int) | sets sort order |
.areaIds([string]) | sets area ids to search for |
.private(boolean) | true if you want to search for private advertisements, false for retailer's |
.getURL() | get URL with the currently set variables |
.search() | executes search -> returns Promise |
Getting constants
There are constants for the conditions and transfer types. The contants are saved as properties of the module object. Example:
const willhaben = require('willhaben')
Property | Constant Description |
---|---|
.getConditions | get the integer for a condition |
.getTransferTypes | get the integer for a transfer type |
.getSortOrders | get the integer for a sort order |
.getAreaIds | get area ids |
Getting Categories
There is a scraper that fetches all categories from willhaben and saves them into a .json file. (file will be saved in project root and is called categories.json) There is already a file with scraped categories in the repo.
scrapeCategories()
There are two ways to get category information, either you search categories by name (There can be multiple categories with the same name, so be aware of that) or by id.
getCategoriesByName(categoryName)
getCategoryById(categoryId)
This example searches for rtx
in the Grafikkarten
category and will show the first 1000 results. (same example as above)
const willhaben = require('willhaben')
willhaben.new()
.keyword('rtx')
.count(1000) // default is 100
.category(willhaben.getCategories.grafikkarten)
.search().then(json => {
console.log(json)
})