2

Since some time, I try to extract the following table from the webpage.

I am trying to get into the //tr objects for the distinct pages on the site (1-8). I managed to store and open the pages, and want to loop over the tables tbody, which holds the //tr objects representing the rows of information that I would like to access:

When running the following code, however, I only get the first entrance from all the 8 pages.

# Imports required for explicit waits

from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import pandas as pd
import time

webside = 'https://www.xxx.dk/find-arkitekt?display_view=block_3&field_company_region=All'

driver = webdriver.Chrome(executable_path=r'C:\Users\KristerJens\Downloads\chromedriver_win32\chromedriver')
driver.implicitly_wait(10)    
driver.get(webside)    
wait = WebDriverWait(driver,10)

# Cookie Accept

driver.execute_script("arguments[0].click();", wait.until(EC.element_to_be_clickable((By.XPATH, "//button[@class='agree-button eu-cookie-compliance-default-button']"))))

# Get pages from products to Extract information from product web pages

pages = []

for page in driver.find_elements_by_xpath("//div[@class='pagination']//ul[@class='pager__items js-pager__items list-pages']//li"):
    pages.append(page.find_element_by_tag_name('a').get_attribute("href"))
    
for i in pages:
    driver.get(i)
    
    options = driver.find_element_by_xpath("//div[@class='architect-view-table']//table[@class='cols-5 responsive-enabled']//tbody//tr")
    
    virk=[]
    post=[]
    by=[]
    web=[]
    mail=[]    
    
    for opt in options:
        print(opt)
        virk.append(driver.find_element_by_xpath("//div[@class='architect-view-table']//table[@class='cols-5 responsive-enabled']//thead//th[@class='icon-markunread-mailbox priority-low views-align-left views-field views-field-field-company-zip views-align-left']").text)
        post.append(driver.find_element_by_xpath("//div[@class='architect-view-table']//table[@class='cols-5 responsive-enabled']//thead//th[@class='icon-markunread-mailbox priority-low views-align-left views-field views-field-field-company-zip views-align-left']").text)
        by.append(driver.find_element_by_xpath("//div[@class='architect-view-table']//table[@class='cols-5 responsive-enabled']//thead//th[@class='icon-markunread-mailbox priority-low views-align-left views-field views-field-field-company-zip views-align-left']").text)
        web.append(driver.find_element_by_xpath("//div[@class='architect-view-table']//table[@class='cols-5 responsive-enabled']//thead//th[@class='icon-markunread-mailbox priority-low views-align-left views-field views-field-field-company-zip views-align-left']").text)
        mail.append(driver.find_element_by_xpath("//div[@class='architect-view-table']//table[@class='cols-5 responsive-enabled']//thead//th[@class='icon-markunread-mailbox priority-low views-align-left views-field views-field-field-company-zip views-align-left']").text)

How can I access all the rows from the dinstinct tables with class="cols-5 responsive-enabled" on all the 8 pages?

I tried so long now so any help is much appreciated!

1

1 Answer 1

1

To scrape the Virk, Post, By, Web and Mail information you can use the Locator Strategies:

Code Block:

driver = webdriver.Chrome(executable_path=r'C:\WebDriver\ChromeDriver\chromedriver.exe', options=options)
driver.get("https://www.danskeark.dk/find-arkitekt?display_view=block_3&field_company_region=All")
virks = [my_elem.text for my_elem in WebDriverWait(driver, 20).until(EC.visibility_of_all_elements_located((By.XPATH, "//td[@headers='view-title-1-table-column']")))]
posts = [my_elem.text for my_elem in WebDriverWait(driver, 20).until(EC.visibility_of_all_elements_located((By.XPATH, "//td[@headers='view-field-company-zip-table-column']")))]
bys = [my_elem.text for my_elem in WebDriverWait(driver, 20).until(EC.visibility_of_all_elements_located((By.XPATH, "//td[@headers='view-field-company-town-table-column']")))]
webs = [my_elem.text for my_elem in WebDriverWait(driver, 20).until(EC.visibility_of_all_elements_located((By.XPATH, "//td[@headers='view-field-company-website-1-table-column']")))]
mails = [my_elem.text for my_elem in WebDriverWait(driver, 20).until(EC.visibility_of_all_elements_located((By.XPATH, "//td[@headers='view-field-company-email-1-table-column']")))]
for i,j,k,l,m in zip(virks, posts, bys, webs, mails):
    print(f"Virk:{i} Post:{j} By:{k} Web:{l} Mail:{m}")
driver.quit()

Console Output:

Virk:& Wainø IVS Post:2400 By:København NV Web: Mail:[email protected]
Virk:1:1 landskab ApS Post:2500 By:Valby Web:www.1til1landskab.dk Mail:[email protected]
Virk:2r arkitekter ApS Post:2100 By:København Ø Web:www.2r-arkitekter.dk Mail:[email protected]
Virk:3XN A/S Post:1437 By:København K Web:www.3xn.dk Mail:[email protected]
Virk:A-PLAN Arkitekter Post:4800 By:Nykøbing F Web:www.a-plan.dk Mail:[email protected]
Virk:a-tjek skive aps Post:7860 By:Spøttrup Web:www.a-tjek.dk Mail:[email protected]
Virk:A.BECH ApS Post:2200 By:København N Web: Mail:[email protected]
Virk:A.R.K. Rådgivning v/Steen Stougård Post:8240 By:Risskov Web: Mail:[email protected]
Virk:A1 Tegnestue ApS Post:5210 By:Odense NV Web:www.a1tegnestue.dk Mail:[email protected]
Virk:Aaberg Arkitekter Post:2450 By:København SV Web:www.aabergarkitekter.dk Mail:[email protected]
Virk:Aagaard Landskab Post:2800 By:Kongens Lyngby Web:www.aagaardlandskab.dk Mail:[email protected]
Virk:AART architects DK A/S Post:8000 By:Aarhus C Web:www.aart.dk Mail:[email protected]
Virk:Abildskov Arkitekter Post:2720 By:Vanløse Web: Mail:[email protected]
Virk:Abrahamsen - Arkitekt & Bygherrerådgivning Post:4600 By:Køge Web:www.aogb.dk Mail:[email protected]
Virk:Adam Trier Jacobsen Arkitekt & Designer ApS Post:2920 By:Charlottenlund Web: Mail:[email protected]
Virk:ADEPT ApS Post:2200 By:København N Web:www.adept.dk Mail:[email protected]
Virk:Adham Architects I/S Post:9490 By:Pandrup Web:www.adhamarchitects.dk Mail:[email protected]
Virk:AG5 A/S Post:1304 By:København K Web:www.ag5.dk Mail:[email protected]
Virk:AI A/S Post:1432 By:København K Web:www.ai.dk Mail:[email protected]
Virk:Aim-Byliv Post:2000 By:Frederiksberg Web:www.aim-byliv.dk Mail:[email protected]
Virk:Aj Arkitekten v/ Jan Ravn Post:8920 By:Randers NV Web:www.ajark.dk Mail:[email protected]
Virk:AK83 Arkitekter A/S Post:2635 By:Ishøj Web:www.ak83.dk Mail:[email protected]
Virk:Albjerg & Buchardt Arkitekter ApS Post:1159 By:København K Web:www.abarkitekter.dk Mail:[email protected]
Virk:Alex Poulsen Arkitekter A/S Post:2200 By:København N Web:www.alexpoulsen.dk Mail:[email protected]
Virk:Alex Rosendal`s Tegnestue Post:2100 By:København Ø Web:www.ar-tegnestue.dk Mail:[email protected]
Virk:AMAS ARKITEKTER Post:2830 By:Virum Web:amasark.dk Mail:[email protected]
Virk:Anders Barslund Post:2830 By:Virum Web:andersbarslund.com Mail:[email protected]
Virk:Anders Brix arkitekt maa mdd professor Post:2800 By:Kongens Lyngby Web:www.andersbrix.dk Mail:[email protected]
Virk:Anders Jørgensen Arkitekter A/S Post:1169 By:København K Web:www.ajas.eu Mail:[email protected]
Virk:Andersen & Sigurdsson Arkitekter Post:1850 By:Frederiksberg C Web:www.a-s.dk Mail:[email protected]
Virk:Anette Meldgaard arkitekt maa Post:2800 By:Kongens Lyngby Web:www.anettemeldgaard.dk Mail:[email protected]
Virk:Animulas Post:8220 By:Brabrand Web:animulas.com Mail:[email protected]
Virk:Anna Mette Exner Arkitektur ApS Post:8220 By:Brabrand Web:www.exnerarkitektur.dk Mail:[email protected]
Virk:Anne Stausholm Landskabsarkitekter Post:4000 By:Roskilde Web:www.annestausholm.dk Mail:[email protected]
Virk:aNNeKS ApS Post:4200 By:Slagelse Web:www.anneks.org Mail:[email protected]
Virk:ANNOARK ApS Post:3660 By:Stenløse Web:www.annoark.dk Mail:[email protected]
Virk:ANS Arkitektfirma Post:8643 By:Ans By Web:www.ansarkitektfirma.dk Mail:[email protected]
Virk:AQDO, Anne Qvist Design Office Post:8000 By:Aarhus C Web:www.aqdo.dk Mail:[email protected]
Virk:Ar-Kon ApS Post:8380 By:Trige Web:www.ar-kon.dk Mail:[email protected]
Virk:arch wiberg Post:3050 By:Humlebæk Web:archwiberg.dk Mail:[email protected]
Virk:Archifield Arkitekterne ApS Post:5600 By:Faaborg Web:www.archifield.dk Mail:[email protected]
Virk:Archinet KS Post:8700 By:Horsens Web: Mail:[email protected]
Virk:Architect Mads Max Ibenfeldt Post:3150 By:Hellebæk Web:madsibenfeldt.com Mail:[email protected]
Virk:Archtrojborg Post:8320 By:Mårslet Web:arch-trojborg.dk Mail:[email protected]
Virk:ArcHus Arkitektfirma ApS Post:8560 By:Kolind Web:www.new-world.dk Mail:[email protected]
Virk:ARCnordic A/S Post:3400 By:Hillerød Web:www.arcnordic.dk Mail:[email protected]
Virk:Arcvision ApS Post:8660 By:Skanderborg Web:www.arcvision.dk Mail:[email protected]
Virk:Arde ApS Post:7400 By:Herning Web:www.arde.dk Mail:[email protected]
Virk:Ardess ApS Post:8000 By:Aarhus C Web:www.ardess.dk Mail:[email protected]
Virk:Arends Arkitekter IVS Post:2820 By:Gentofte Web:www.arends.dk Mail:[email protected]
Virk:ARK+ Post:7100 By:Vejle Web:www.ark-plus.dk Mail:[email protected]
Virk:Arkikon ApS Post:8500 By:Grenaa Web:www.arkikon.dk Mail:[email protected]
Virk:Arkimentor ApS Post:6040 By:Egtved Web:www.arkimentor.dk Mail:[email protected]
Virk:Arkiplus Post:4180 By:Sorø Web:www.arkiplus.dk Mail:[email protected]
Virk:Arkitekt Bjarne Korsgaard Post:2830 By:Virum Web: Mail:[email protected]
Virk:arkitekt Daniel Nielsen Post:2000 By:Frederiksberg Web:www.arkitektdn.dk Mail:[email protected]
Virk:Arkitekt Esben Colding Broe Post:7700 By:Thisted Web: Mail:[email protected]
Virk:Arkitekt Jarl ApS Post:7100 By:Vejle Web: Mail:[email protected]
Virk:Arkitekt Jesper Brask ApS Post:3400 By:Hillerød Web:brask-leonhardt.dk Mail:[email protected]
Virk:Arkitekt Kristine Jensens Tegnestue Post:8000 By:Aarhus C Web:www.kristinejensen.dk Mail:[email protected]
Virk:Arkitekt Lars Remfeldt ApS Post:2791 By:Dragør Web: Mail:[email protected]
Virk:Arkitekt Lise Juel ApS Post:3100 By:Hornbæk Web:www.lisejuel.dk Mail:[email protected]
Virk:Arkitekt MAA Anker Ravn Knudsen Post:6630 By:Rødding Web:www.ankerravnknudsen.dk Mail:[email protected]
Virk:Arkitekt MAA Birthe Just Post:2820 By:Gentofte Web:www.bj-ark.dk Mail:[email protected]
Virk:Arkitekt MAA Boe Fischer Post:5230 By:Odense M Web:www.boefischer.dk Mail:[email protected]
Virk:Arkitekt MAA Christoffer Storm Post:2610 By:Rødovre Web: Mail:[email protected]
Virk:Arkitekt MAA Finn Strabo Post:3150 By:Hellebæk Web:www.strabo.dk Mail:[email protected]
Virk:Arkitekt MAA Jan Harboe Post:1455 By:København K Web:www.janharboe.dk Mail:[email protected]
Virk:Arkitekt MAA Jens Høg Post:4621 By:Gadstrup Web: Mail:[email protected]
Virk:Arkitekt MAA Jens Lind Post:2100 By:København Ø Web:www.jens-lind.dk Mail:[email protected]
Virk:Arkitekt MAA Jens Stensgaard Post:8660 By:Skanderborg Web: Mail:[email protected]
Virk:Arkitekt MAA John Kronborg Christensen Post:6430 By:Nordborg Web: Mail:[email protected]
Virk:Arkitekt MAA Keld Wohlert Post:2680 By:Solrød Strand Web: Mail:[email protected]
Virk:Arkitekt MAA Knud Erik Møller Post:9800 By:Hjørring Web:www.kem-arkitekter.dk Mail:[email protected]
Virk:Arkitekt MAA Mathilde Petri Post:2830 By:Virum Web: Mail:[email protected]
Virk:Arkitekt MAA Morten Kjelstrup Post:1054 By:København K Web: Mail:[email protected]
Virk:Arkitekt MAA Niels Vestergaard Post:8960 By:Randers SØ Web: Mail:[email protected]
Virk:Arkitekt maa Pierre Devriel Post:4500 By:Nykøbing Sj Web:www.tegnestuen-nordkyst.com Mail:[email protected]
Virk:Arkitekt MAA Steffen M.Søndergaards Tegnestue ApS Post:6600 By:Vejen Web: Mail:[email protected]
Virk:Arkitekt maa Steffen Søby aps Post:5700 By:Svendborg Web:www.soeby.dk Mail:[email protected]
Virk:Arkitekt MAA Tom Sjørup Post:3670 By:Veksø Sjælland Web: Mail:[email protected]
Virk:Arkitekt MAA Torben Baltsen Post:2720 By:Vanløse Web:www.torbenbaltsen.dk Mail:[email protected]
Virk:Arkitekt MAA Tummas Niclasen Post:2830 By:Virum Web:www.niclasen.eu Mail:[email protected]
Virk:Arkitekt Michael Kornbeck Post:1432 By:København K Web:www.kornbeckbonde.dk Mail:[email protected]
Virk:Arkitekt Stefan Vesti Brorsen Post:2300 By:København S Web:asvb.dk Mail:[email protected]
Virk:arkitekt thomas riis aps Post:3905 By:Nuussuaq Web: Mail:[email protected]
Virk:Arkitekt Thomas Thomsen DanskeArk Post:7000 By:Fredericia Web:www.tt-arkitekt.dk Mail:[email protected]
Virk:Arkitektanpartsselskabet Ole Fabricius Post:6760 By:Ribe Web:www.ole-fabricius.dk Mail:[email protected]
Virk:Arkitekter Syd ApS Post:6270 By:Tønder Web:www.arkitektersyd.dk Mail:[email protected]
Virk:Arkitekterne Bahn v/Erik Bahn Post:4070 By:Kirke Hyllinge Web:www.arkitekterne-bahn.dk Mail:[email protected]
Virk:Arkitekterne Bahn v/Leif Bahn Post:4300 By:Holbæk Web: Mail:[email protected]
Virk:Arkitekterne Fuglehuset Post:4320 By:Lejre Web: Mail:[email protected]
Virk:Arkitekterne Holst v/Michael Holst Post:1202 By:København K Web: Mail:[email protected]
Virk:Arkitekterne KØGE A/S Post:4600 By:Køge Web:www.arkk.dk Mail:[email protected]
Virk:Arkitekterne Vejen A/S Post:6100 By:Haderslev Web:www.arkitekternevejen.dk Mail:[email protected]
Virk:Arkitektfirma A/S Hune & Elkjær Post:8000 By:Aarhus C Web:www.h-e.dk Mail:[email protected]
Virk:ARKITEKTFIRMA BYDER ApS Post:2820 By:Gentofte Web:www.byder.dk Mail:[email protected]
Virk:Arkitektfirma Christen Justesen A/S Post:9990 By:Skagen Web:www.christenjustesen.dk Mail:[email protected]
Virk:Arkitektfirma Claus Jensen ApS Post:8000 By:Aarhus C Web:www.cj-arkitekter.dk Mail:[email protected]
Virk:Arkitektfirma Knud Erik Holst MAA / DA Post:4200 By:Slagelse Web:www.arkitekt-holst.dk Mail:[email protected]
Sign up to request clarification or add additional context in comments.

1 Comment

You are amazing DebanjanB!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.