I need to scrape this site. The first thing I have to do is to search using each of the elements of 'Licensee Name' dropdown listbox.
I tried the following code, but it's not working (I tried using the class attribute, but it's not working either):
#importing required libraries
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.remote.webelement import WebElement
from selenium.webdriver.support.wait import WebDriverWait
from selenium_move_cursor.MouseActions import move_to_element_chrome
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
import js
import json
import numpy as np
import time
import pandas as pd #to save CSV file
from bs4 import BeautifulSoup
import ctypes #to create text popup
#defining browser and adding the “ — headless” argument
opts = Options()
prefs = {"profile.default_content_setting_values.notifications" : 2}
opts.add_experimental_option("prefs",prefs)
opts.add_argument(' — headless')
driver = webdriver.Chrome('C:/chromedriver_win32/chromedriver', options=opts)
url = 'https://www.mga.org.mt/licences/'
driver.maximize_window() #maximize the window
driver.get(url) #open the URL
driver.implicitly_wait(440) #maximum time to load the link
elem=driver.find_element(By.XPATH, "//input[@aria-activedescendant='select2-ListBox3-result-9y2z-Air Dice Services Malta Ltd']").input()
elem
Pls help me with this. I mainly need to get the list of items in the dropdown list, and then search using them one by one.
CodePudding user response:
All the License Names can be collected as following:
Sinse that block is inside the iframe you first need to switch into that iframe.
Then you can click on the drop-box, get the list of opened elements and get their texts, as following.
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
options = Options()
options.add_argument("start-maximized")
webdriver_service = Service('C:\webdrivers\chromedriver.exe')
driver = webdriver.Chrome(options=options, service=webdriver_service)
wait = WebDriverWait(driver, 10)
url = "https://www.mga.org.mt/licences/"
driver.get(url)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, "//iframe[contains(@src,'//mgali')]")))
wait.until(EC.element_to_be_clickable((By.XPATH, "//span[@id='select2-ListBox3-container']"))).click()
names = []
options = wait.until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, ".select2-results__options li")))
for option in options:
names.append(option.text)
print(names)
The result is:
['1x2 NETWORK MALTA LTD', '21 Heads Up Limited', '4Tune-Software GmbH', 'ABRASERVE LIMITED', 'AG Software Limited', 'AGSi Malta Limited', 'Air Dice Services Malta Ltd', 'Alea Malta Limited', 'Altenar Software Limited', 'AMGO iGaming Malta Ltd', 'Amusnet Gaming Limited', 'Anderson Gambling Ltd.', 'Apollo Entertainment Limited', 'Apollo Net Ltd', 'Apollo Soft Limited', 'Apparat Gaming Services Limited', 'APPRICOTTA LIMITED', 'Aqua Vitae Ltd', 'Arcadia GS (Cyprus) Ltd', 'Argo Gaming Limited', 'Ash Gaming Limited', 'Askott Entertainment (Malta) Limited', 'Aspire Global International Limited', 'ATHENA01 LTD', 'Atlantic Games Malta Limited', 'Authentic Gaming Malta Ltd', 'Avento MT Limited', 'B2B Gaming Services (Malta) Limited', 'Bayton Limited', 'Bede Gaming Malta Limited', 'Best Gaming Technology GmbH', 'Bestbet Limited', 'Bestplay Gaming Limited', 'Bet Studios Limited', 'Betago Limited', 'Bet-At-Home.com Entertainment Limited', 'bet-at-home.com International Limited', 'Bet-at-home.com Internet Limited', 'BetDino Limited', 'Betfair Casino Limited', 'Betfair International PLC', 'Bethard Group Limited', 'BetIt Operations Limited', 'Betkick Sportwettenservice Gmbh', 'Betsson Platform Solutions Limited', 'BettingCloud Limited', 'Betway Limited', 'BeyondPlay Gaming Holding Ltd.', 'Bingo Limited', 'Bitsurf Consulting Limited', 'BLACKBERRY SOFTWARE LIMITED', 'BLC SYSTEMS LIMITED', 'BluBet Operations Ltd.', 'BLUE RIBBON SOFTWARE MALTA LIMITED', 'Blueprint Technologies (Malta) Ltd', 'BM Solutions Limited', 'BML Group Limited', 'BOA Solutions Limited', 'Booming Games (Malta) Limited', 'BP Group Limited', 'Broadway Gaming Limited', 'Buddybet Malta Limited', 'Bulex Enterprises (Malta) Limited', 'BV (Germany) Limited', 'bwin (Deutchland) Limited', 'bwin Holdings (Malta) Limited', 'bwin.gr Limited', 'bwin.party services (Malta) Limited', 'Cabot Cove 03 Limited', 'Carranza Trading Limited', 'Cashpoint Malta Limited', 'Cashpoint Solutions Malta Ltd', 'Casino Malta Limited', 'CASINOSTUGAN LTD', 'Casumo Services Limited', 'Casumo Spain P.L.C', 'Chilling Cheetah Limited', 'Claymore Malta Limited', 'Clobet LTD', 'Codere Online Management Services Limited', 'Codere Online Operator Limited', 'Co-Gaming Limited', 'COGG Studios Limited', 'Cognita Technologies Limited', 'COMEON SWEDEN LTD', 'Condor Malta Limited', 'Corona Limited', 'Crown DFS Malta Limited', 'CS Litto Limited', 'Cyan Blue International Limited', 'Cyberplay Management Limited', 'Darwin Gaming Limited', 'Daylight Limited', 'Dazzletag Entertainment Limited', 'Delasport Limited', 'Development MT Limited', 'Dialmedia Limited', 'Diamond Link Limited', 'Digimedia Limited', 'Digitain (MT) Limited', 'Digital Software Limited', 'Diomedes Limited', 'Dragonara Gaming Limited', 'DS Virtual Gaming Limited', 'Dumarca Gaming Limited', 'Dumarca Live Limited', 'Dunder Limited', 'E.G.G. Limited', 'Earlybird Limited', 'Eastrock Valley Solutions Limited', 'edict eGaming GmbH', 'Edict Malta Limited', 'EGC SERVICES LIMITED', 'EGMIT Elite Limited', 'EGS International Limited', 'Elec Games C1 Limited', 'ElectraWorks (Kiel) Limited', 'ElectraWorks (Svenska) Limited', 'ElectraWorks Europe Limited', 'ElectraWorks Limited', 'Elk Studios Malta Limited', 'ELLMOUNT ENTERTAINMENT LTD', 'Endorphina Limited', 'Entain (Romania) Limited', 'Entain Operations Limited', 'Esports Entertainment (Malta) Limited', 'ETO Limited', 'European Lotto and Betting Limited', 'Evenbet Gaming Ltd', 'Everum Limited', 'Everymatrix Software Limited', 'Evoke Gaming Limited', 'Evolution Alderney Limited', 'Evolution Gaming Malta Limited', 'Evolution Malta Limited', 'Evolution NetEnt Malta Limited', 'Evolution Red Tiger International Limited', 'Evolution Red Tiger Malta Limited', 'Eyas Gaming Limited', 'Eyecon Alderney Limited', 'Fair Play Bets Limited', 'FairBet Limited', 'Fairload Limited', 'FavBet Limited', 'FBM DIGITAL SYSTEMS LIMITED', 'Football 1x2 LTD', 'Forseti Services Limited', 'Friston Limited', 'FS Software Ltd', 'FUGASO Limited', 'GAMART LIMITED', 'Game Tower Entertainment Limited', 'Gamebookers (Deutschland) Limited', 'Games Inc Services Limited', 'GAMESOFT LTD', 'Gaming Corps Malta Ltd', 'Gaming Operations Limited', 'Gaming Technology Solutions', 'Gammix Limited', 'Gazelle Co. Limited', 'Gears of Leo A.B.', 'Geco Gaming Limited', 'Geco Gaming Pty Limited', 'Geneity Limited', 'Genesis Bluebird SP ZOO', 'Genesis Global Limited', 'Geniusday Trading Limited', 'Geokul Limited', 'Get Lucky Ltd', 'GGC Malta Limited', 'GGN Europe Ltd', 'Glide Limited', 'GLITNOR SERVICES LIMITED', 'Global Gaming Estonia OÜ', 'Global Technology and Sports Limited', 'GM Gaming Limited', 'Goldwin Ltd', 'Grand Play Limited', 'Green Feather Online Limited', 'Green Jade Games Ltd', 'Greentube Malta Limited', 'Greenvest Betting Limited', 'Groove Technologies Malta Ltd.', 'GXMA Limited', 'Habanero Systems Limited', 'Hacksaw Operations Ltd', 'HAJPER LTD', 'Hanson Applied Sciences Limited', 'Helio Gaming Limited', 'Heliopsis Limited', 'HERA01 LTD', 'Hero Bet Ltd', 'Hero Gaming Limited', 'HGIP Ltd', 'HGMT Limited', 'High5games B2B (Malta) Ltd', 'Hiidenkivi Estonia Oü', 'Hillside (Gaming) ENC', 'Hillside (International Gaming) ENC', 'Hillside (International Sports) ENC', 'Hillside (Malta Gaming) ENC', 'Hillside (Malta Sports) ENC', 'Hillside (New Media Malta) Plc', 'Hillside (Sports) ENC', 'Hillside (Technology) Limited', 'Hillside (UK Gaming) ENC', 'Hillside (UK Sports) ENC', 'Hölle Games GmbH', 'Home Gaming Entertainment Limited', 'HPG Interactive Malta Limited', 'HUB88 Limited', 'IBA Casino Limited', 'IBA Entertainment Limited', 'Ice Elite Limited', 'IFLEX LIMITED', 'Iforium (Malta) Limited', 'iGamingCloud Limited', 'IGP Skill Processing Ltd', 'IGT Europe BV', 'IGT Global Services Limited', 'IGT Malta Casino Limited', 'IGT Malta Interactive Limited', 'Infiniza Limited', 'Insipia Limited', 'Inspired Entertainment (Malta) Limited', 'Interwetten Gaming Limited', 'Interwetten International Limited', 'ISB Magma Limited', 'IZI Interactive Limited', 'Kaizen Gaming International Limited', 'Kalamba Games Limited', 'Kambi Malta Limited', 'Kambi Spain PLC', 'Kambi Sports Espana S.L.', 'Kanon Gaming Limited', 'Keep Limited', 'Kinesis Live Ltd', 'Kulumsoft Limited', 'L&L Europe Limited', 'L.C.S Limited', 'L7 Entertainment Limited', 'Ladbrokes (Deutschland) Limited', 'Leap Limited', 'LeoVegas Gaming plc', 'Level Up Interactive Limited', 'Ligtip Limited', 'LIINOO Invest Europe Limited', 'LIVEG24 Ltd', 'Logflex Limited', 'Logflex Ltd', 'Logflex MT Limited', 'Lopoca Gaming Limited', 'Lopoca Holding Limited', 'Lottery Live Limited', 'Lotto Direct Limited', 'Lottomatrix Operations Limited', 'Luckia Entertainment Limited', 'Lucky Stream Limited', 'LVSPORTS LTD', 'Magic Mill Limited', 'Maltix Limited', 'Mangas Gaming Malta Limited', 'Marl Morhaine Solutions Limited', 'Martingale Europe Limited', 'Maxent Limited', 'Media Games Malta (EU) Limited', 'Megapixel Entertainment Limited', 'Meridian Gaming Limited', 'Microgaming Europe Limited', 'Microgaming Malta Limited', 'Mill of Magic Limited', 'Minutelotto Group Ltd', 'MKC Limited', 'ML Entertainment Casino Limited', 'ML Entertainment Gaming Limited', 'MOA GAMING SWEDEN LTD', 'Mobenga AB', 'MOBILE INCORPORATED LIMITED', 'Mobilt Limited', 'Mozzartbet Malta Limited', 'Mr Green Limited', 'Mr Vegas Ltd', 'myLotto24 Limited', 'myLotto24 Ltd (Malta)', 'N1 Aggregator Ltd', 'N1 Games Ltd', 'N1 Interactive Limited', 'National Lottery plc', 'NetBet Enterprises Limited', 'NetPlay Malta Ltd', 'NetX Betting Limited', 'NetXGaming Limited', 'NG Entertainment Limited', 'Ninja Global Limited', 'Nolimit City Limited', 'N-Serve Limited', 'NSUS Malta Limited', 'NSYNC Developments Limited', 'NTEC LIMITED', 'Ocean Star Limited', 'OnAir Entertainment MT Ltd', 'One Casino Limited', 'One Click Limited', 'Online Gaming Solutions Ltd.', 'ONYXION MALTA LIMITED', 'Oring Limited', 'Oryx Gaming Limited', 'OT Malta Limited', 'P2P Entertainment Limited', 'Paddy Power Services Limited', 'Palamedes Limited', 'Palasino Malta Limited', 'Paratu Limited', 'Pariplay Malta Limited', 'Pegma Group SRL', 'PG ENTERTAINMENT MALTA LIMITED', 'PinBet Malta Limited', 'Pinnacle Solutions Ltd.', 'Pixel Digital Ltd', 'Plannatech (Malta) Limited', 'Platin Gaming Limited', 'Play North Limited', 'PlayAnak Limited', 'PlayCherry Limited', 'PLAYGON MALTA LIMITED', 'PLAYMER LTD', "Play'n Go Malta Limited", 'Playtech BGT Sports Limited', 'Playtech Mobile (Cyprus) Limited', 'Playtech P.L.C.', 'Playtech Services (Cyprus) Limited', 'Playtech Software Limited', 'Pocket Games Software Limited', 'Pokerstrategy.com Limited', 'Polar Limited', 'Polco Limited', 'Power Leisure Bookmakers Limited (Irish Branch)', 'PPB Counterparty Services Limited', 'PPB Entertainment Limited', 'PPB Games Limited', 'PPB GE Limited', 'Pragmatic Solutions MT Limited', 'Pragmaticplay Limited', 'Premiergaming Limited', 'Prima Networks Limited', 'Prima Networks Spain PLC', 'Pro Xenon Mediathek Limited', 'Probe Investments Limited', 'Procella Ltd', 'Progressplay Limited', 'Prozone Limited', 'Psi-clone Games Limited', 'PT Hosting Malta Limited', 'PTR Live Technologies SRL', 'Push Gaming Malta Limited', 'Qufan Internet Technology Limited', 'Quickspin AB', 'Quik Gaming Ltd', 'Quik Tech Limited', 'Rabbit Bettertainment Limited', 'Rabbit Entertainment Limited', 'RaceBets International Gaming Limited', 'Rational Live Events (Malta) Limited', 'Ray Gaming Software Ltd', 'RayBet Ltd', 'Realm Entertainment Limited', 'Rebels Gaming Limited', 'Red Panda Ltd', 'Red Rake Tech Sociedad Limitada', 'RED RHINO LTD', 'Red Turtle Ltd', 'Relax Gaming Limited', 'Reshuffle Gaming Limited', 'RFA Malta Limited', 'RFranco Technologies Malta Limited', 'Rhinoceros Operations Limited', 'Rizk Nordic Limited', 'RocketStudios Limited', 'Rootz Ltd', 'Royal Panda Limited', 'RULEO Alpenland AG', 'Rush Gaming Ltd', 'S.P.G Malta LTD', 'SB Software Limited', 'SBTech Malta Limited', 'Scout & Co. Limited', 'Scout Ltd.', 'SFJL Holding Limited', 'SFTG Limited', 'SG Digital Gaming (Malta) Limited', 'Shark77 Limited', 'SILVEREYE ENTERTAINMENT LIMITED', 'Simple Software Limited', 'Skill On Net Limited', 'Skill On Net Ltd.', 'Skill On Net PT Ltd', 'Skillbet Limited', 'SKS365 Malta Limited', 'Skywind Malta Limited', 'Slotmill Limited', 'SLTM Ltd', 'Smarkets Malta Limited', 'SmartSoft Limited', 'SNABBARE LTD', 'Soar Malta Ltd', 'Soft Construct (Malta) Limited', 'SoftGames International Trading Limited', 'Softquo Holding Ltd', 'Sogno Di Tolosa Ltd', 'Spinmatic Limited', 'Spinstars Entertainment Limited', 'Spitch Limited', 'Sportingbet (Deutschland) Limited', 'SportingTech Ltd', 'Sportradar Malta Limited', 'Sports Broker Ltd', 'Sports Broker sp. Z.O.O', 'Sports Information Services Limited', 'Sportsbook Software GmbH', 'Stakelogic B.V.', 'Stakelogic Live Limited', 'Stakelogic Live Netherlands B.V.', 'Stakelogic Malta Limited', 'Stakelogic Romania Limited', 'Stakelogic UK Limited', 'Stanleybet Malta Limited', 'STECH European Entertainment Limited', 'SubTech Ltd', 'Super7plus Limited', 'SuprPlay Ltd', 'Swintt Malta Ltd', 'Synot Games Limited', 'Synot W a.s.', 'Tain Betting Promotion Limited', 'TG LAB, UAB', 'The Lotter Limited', 'The Mill Adventure Limited', 'Thunderkick Malta Limited', 'Tipbet Limited', 'Tipico B2B Limited', 'Tipico Co. Ltd', 'Tipico Frankfurt Limited', 'Tipico Frankfurt Ltd', 'Tipico Games Ltd', 'Tipico Karlsruhe Limited', 'Tipico Karlsruhe Ltd', 'Tipico Muenchen Limited', 'Tipin Ltd', 'Tipster Limited', 'Tipwin Limited', 'Together Gaming Solutions P.L.C.', 'TopGoal (Malta) Ltd.', 'TORNADO GAMES MALTA LTD', 'Torrero Ltd.', 'Totup System Limited', 'Trannel International Limited', 'Trinity Bet Operations', 'True Flip Gaming Ltd', 'True Ltd.', 'TSG Interactive Gaming Europe Limited', 'TSG Platforms (Ireland) Limited', 'Tumas Gaming Limited', 'TV GLOBAL ENTERPRISES LTD', 'Ultracell Ltd', 'United Remote Limited', 'Universe Entertainment Services Malta Limited', 'Uptick Entertainment Malta Limited', 'V.B Video (Cyprus) Limited', 'Ventures Lab Malta Limited', 'VF 2011 Limited', 'VGW GAMES LIMITED', 'Videoslots Limited', 'Videoslots Sports Ltd', 'Viral Interactive Limited', 'Virtual Digital Services Limited', 'Virtual Gaming Technologies Limited', 'Virtue Fusion (Alderny) Limited', 'Virtue Gaming Operations Ltd', 'Vistabet Limited', 'Vivaro Limited', 'Wazdan Limited', 'WHG (International) Ltd', 'White Hat Gaming Limited', 'William Hill Global PLC', 'William Hill Malta PLC', 'Winners Malta Operations Limited', 'Winzon Group Limited', 'World of Sportsbetting Limited', 'XC Gaming Sweden Limited', 'Yggdrasil Gaming Limited', 'Zecure Gaming Limited', 'Zetotesystem Limited', 'Zitro Factory SL', 'Zitro International S.A.R.L.', 'Zitro Malta Limited', 'Zweeler Limited']