From 8723a732cb5c488c625a0370466b526158d73e09 Mon Sep 17 00:00:00 2001 From: "shariar@raenabeauty.com" Date: Thu, 1 Feb 2024 13:09:43 +0400 Subject: [PATCH] FB Marketplace crawler --- fb_marketplace/fb_marketplace_products.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/fb_marketplace/fb_marketplace_products.py b/fb_marketplace/fb_marketplace_products.py index 6d0d8c4..7f1856f 100644 --- a/fb_marketplace/fb_marketplace_products.py +++ b/fb_marketplace/fb_marketplace_products.py @@ -68,10 +68,23 @@ class FbMarketplaceProducts: products = [] for element in product_elements: try: - name = element.find_element(By.CSS_SELECTOR, ".x1lliihq.x6ikm8r.x10wlt62.x1n2onr6").text - price = element.find_element(By.CSS_SELECTOR, ".x193iq5w.xeuugli.x13faqbe.x1vvkbs.xlh3980.xvmahel.x1n0sxbx.x1lliihq.x1s928wv.xhkezso.x1gmr53x.x1cpjm7i.x1fgarty.x1943h6x.x4zkp8e.x3x7a5m.x1lkfr7t.x1lbecb7.x1s688f.xzsf02u").text + try: + name = element.find_element(By.CSS_SELECTOR, ".x1lliihq.x6ikm8r.x10wlt62.x1n2onr6").text + except: + pass + + try: + price = element.find_element(By.CSS_SELECTOR, ".x193iq5w.xeuugli.x13faqbe.x1vvkbs.x10flsy6.x1lliihq.x1s928wv.xhkezso.x1gmr53x.x1cpjm7i.x1fgarty.x1943h6x.x1tu3fi.x3x7a5m.x1lkfr7t.x1lbecb7.x1s688f.xzsf02u").text + except: + pass + url = element.find_element(By.TAG_NAME, 'a').get_attribute("href") - city = element.find_element(By.CSS_SELECTOR, ".x1lliihq.x6ikm8r.x10wlt62.x1n2onr6.xlyipyv.xuxw1ft").text + + try: + city = element.find_element(By.CSS_SELECTOR, ".x1lliihq.x6ikm8r.x10wlt62.x1n2onr6.xlyipyv.xuxw1ft").text + except: + pass + flag = 0 product = [name, price, url, city, flag] products.append(product)