Leboncoin extractor avatar
Leboncoin extractor
Try for free

3 days trial then $19.00/month - No credit card required now

View all Actors
Leboncoin extractor

Leboncoin extractor

anchor/leboncoin
Try for free

3 days trial then $19.00/month - No credit card required now

Extract information from leboncoin.fr : no limitation, you get fast results in CSV, Excel... or API format. Le meilleur outil de scrapping pour leboncoin

The code examples below show how to run the Actor and get its results. To run the code, you need to have an Apify account. Replace <YOUR_API_TOKEN> in the code with your API token, which you can find under Settings > Integrations in Apify Console. Learn more

1from apify_client import ApifyClient
2
3# Initialize the ApifyClient with your Apify API token
4client = ApifyClient("<YOUR_API_TOKEN>")
5
6# Prepare the Actor input
7run_input = {
8    "startUrls": [{ "url": "https://www.leboncoin.fr/recherche?category=21&text=mer&price=17-50" }],
9    "pageFunction": """async function pageFunction(context) {
10    let data = {}
11    let userData = context.request.userData
12    data.url = context.request.url
13    data.label = userData.label
14
15    let items = await context.page.evaluate(() => {
16        const item = $('[data-qa-id=aditem_container]')
17        const itemInfo = item.map(function(i,elem) {
18            let obj = {}
19            obj.title = $(this).find('[data-qa-id=aditem_title]').text()
20            obj.price = $(this).find('[data-test-id=price]').text()
21            obj.location = $(this).find('span[aria-label], p[aria-label]').filter(function() { return this['aria-label']?.match(/[0-9]{5}/);}).text()
22            obj.date = $(this).find('span[aria-label], p[aria-label]').filter(function() { return this.title?.match(/:/);}).text()
23            obj.img = $(this).find('a img:first').attr('src')
24            obj.rank = i+1
25            return obj
26        }).get()
27        return itemInfo
28    })
29    let itemsWithDataProp = items.map(obj => { 
30        for(const key of Object.keys(data) ){
31            obj[key] = data[key]
32        }
33        return obj
34    })
35    return itemsWithDataProp;
36}
37""",
38    "proxyConfiguration": {
39        "useApifyProxy": True,
40        "apifyProxyGroups": ["RESIDENTIAL"],
41        "apifyProxyCountry": "FR",
42    },
43}
44
45# Run the Actor and wait for it to finish
46run = client.actor("anchor/leboncoin").call(run_input=run_input)
47
48# Fetch and print Actor results from the run's dataset (if there are any)
49print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
50for item in client.dataset(run["defaultDatasetId"]).iterate_items():
51    print(item)
52
53# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start
Developer
Maintained by Community
Actor metrics
  • 16 monthly users
  • 4 stars
  • 100.0% runs succeeded
  • Created in Oct 2021
  • Modified 3 months ago