Skip to content

Commit

Permalink
fixed css selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
Maazasim1 committed Sep 18, 2023
1 parent 258c0b7 commit adfcccc
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def get_page_source(self, url):

# Wait for the page to load.
WebDriverWait(self.browser, 10).until(EC.presence_of_element_located(
(By.CSS_SELECTOR, "div[class=' x1gslohp x1e56ztr']")))
(By.CSS_SELECTOR, "div[class='x9f619 x1n2onr6 x1ja2u2z']")))

for i in range(1, 5):
# Scroll down to the bottom of the page to load all items.
Expand Down Expand Up @@ -121,21 +121,24 @@ def scrape_facebook_marketplace(self):
soup = BeautifulSoup(page_source, 'html.parser')

# Get the items.
div = soup.find_all('div', class_='x9f619 x78zum5 x1r8uery xdt5ytf x1iyjqo2 xs83m0k x1e558r4 x150jy0e xnpuxes x291uyu x1uepa24 x1iorvi4 xjkvuk6')

div = soup.find_all('div', class_='x9f619 x78zum5 x1r8uery xdt5ytf x1iyjqo2 xs83m0k x1e558r4 x150jy0e '
'x1iorvi4 xjkvuk6 xnpuxes x291uyu x1uepa24')
print(div[0].find('span', class_='x1lliihq x6ikm8r x10wlt62 x1n2onr6 xlyipyv xuxw1ft').text.strip())


# Iterate through the items.
for d in div:
try:
# Get the item image.
image = d.find('img', class_='xt7dq6l xl1xv1r x6ikm8r x10wlt62 xh8yej3')['src']
image = d.find('img', class_='xt7dq6l')['src']
# Get the item title from span.
title = d.find('span', 'x1lliihq x6ikm8r x10wlt62 x1n2onr6').text
# Get the item price.
price = d.find('span', 'x193iq5w xeuugli x13faqbe x1vvkbs x1xmvt09 x1lliihq x1s928wv xhkezso x1gmr53x x1cpjm7i x1fgarty x1943h6x xudqn12 x676frb x1lkfr7t x1lbecb7 x1s688f xzsf02u').text
price = d.find('span', class_='x193iq5w xeuugli x13faqbe x1vvkbs xlh3980 xvmahel x1n0sxbx x1lliihq x1s928wv xhkezso x1gmr53x x1cpjm7i x1fgarty x1943h6x x4zkp8e x3x7a5m x1lkfr7t x1lbecb7 x1s688f xzsf02u').text.strip()
# Get the item URL.
url = d.find('a', class_='x1i10hfl xjbqb8w x6umtig x1b1mbwd xaqea5y xav7gou x9f619 x1ypdohk xt0psk2 xe8uvvx xdj266r x11i5rnm xat24cr x1mh8g0r xexx8yu x4uap5 x18d9i69 xkhd6sd x16tdsg8 x1hl2dhg xggy1nq x1a2a7pz x1heor9g x1lku1pv')['href']
# Get the item location.
location = d.find('span', 'x1lliihq x6ikm8r x10wlt62 x1n2onr6 xlyipyv xuxw1ft x1j85h84').text
location = d.find('span', class_='x1lliihq x6ikm8r x10wlt62 x1n2onr6 xlyipyv xuxw1ft').text.strip()

# Print the item information.
print(f"Image: {image}")
Expand Down Expand Up @@ -197,4 +200,4 @@ def scrape_marketplace(self):
app = MainWindow()
app.mainloop()



0 comments on commit adfcccc

Please sign in to comment.