I'm trying to scrape the phone number from a page. One such page is this. All the pages contain a link button with text SEE PHONE NUMBER, clicking on which reveals the phone number. I'm trying to scrape that particular phone number. Here is what I've tried so far :
company_url = 'https://www.europages.co.uk/PORT-INTERNATIONAL-GMBH/00000004710372-508993001.html'
d = {}
try :
options = webdriver.FirefoxOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument('--incognito')
options.add_argument('--headless')
driver = webdriver.Firefox(options=options)
driver.get(company_url)
link = driver.find_element_by_link_text('See phone number')
link.click()
driver.close()
page = driver.page_source
soup = bs(page, 'html.parser')
tel_no = soup.find('div', {'class' : 'info-tel-num'})
tel_no = tel_no.text
d['telephone'] = tel_no
except Exception as e:
print(f'Error encountered : {e}')
But every time, it prints this error in the exception block :
Error encountered : Message: Unable to locate element: See phone number
This link button doesn't have any particular id or class, so I can't use find_element_by_id or find_element_by_class. Here is what I found by inspect element on that button (before clicking):
And here is the inspect element result after clicking the button :



link.click()if the failure is in the line before? it's probably page loading timing issue, you need to wait before trying to locate the element. - Guy