I am receiving the href links on some links and others returned None value.
I have the following snippet to retrieve the first 16 items on a page:
def loop_artikelen ():
artikelen = driver.find_elements(By.XPATH, "//*[@id='content']/div[2]/ul/li")
artikelen_lijst = []
for artikel in artikelen[0:15]:
titel = artikel.find_element(By.CLASS_NAME, 'hz-Listing-title').text
prijs = artikel.find_element(By.CLASS_NAME, 'hz-Listing-price').text
link = artikel.find_element(By.CLASS_NAME, 'hz-Listing-coverLink').get_attribute('href')
#if link == "None":
# link = artikel.find_element(By.XPATH(".//a").get_attribute('href'))
artikel = titel, prijs, link
artikelen_lijst.append(artikel)
The output looks like this when i print it out
('Fiets gestolen dus voor een mooi prijsje is ie van jou', '€ 400,00', None)
('Amslod middenmoter fiets', '€ 1.500,00', None)
('Batavus damesfiets', '€ 90,00', 'https://www.marktplaats.nl/v/fietsen-en-brommers/fietsen-dames-damesfietsen/m1933195519-batavus-damesfiets')
('Time edge', '€ 700,00', 'https://www.marktplaats.nl/v/fietsen-en-brommers/fietsen-racefietsen/m1933185638-time-edge')
I tried adding a time.sleep(2) between link and artikel, but it didn't work. You can also i tried something else after "#", that didn't work either.
Who can help me?
Thanks in advance
Link to site : https://www.marktplaats.nl/q/fiets/#offeredSince:Vandaag|sortBy:SORT_INDEX|sortOrder:DECREASING|