-1

I'm trying to scrape a webpage to get the contact number everything works fine but i want to run the script in "--headless" mode but when i do with this option i'm getting error. But it works when i disable --headless mode.

My code :

import time
from bs4 import BeautifulSoup
from selenium import webdriver 
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--headless")

#options.add_argument('--disable-gpu')  # maybe needed if running on Windows.
driver = webdriver.Chrome(executable_path='/home/dobuyme/Desktop/chromedriver', options=chrome_options)
print("Loading Page...")
driver.get('https://www.example.com')
time.sleep(5)
show_number_btn_xpath = '//span[contains(text(),"Show number")]'
sk = driver.find_element_by_xpath(show_number_btn_xpath)
sk.click()

soup = BeautifulSoup(driver.page_source,"html.parser")
title = soup.find("span", {"class": ["_truncate_multilines multiline_truncation"]}).get_text()
app = soup.find("div", {"class": ["_top_row-destop text-left"]}).find("h2").get_text().strip()
driver.quit()
contact = soup.find("div", {"class": ["_user_contact"]}).find("p", {"class": ["_call text-left"]}).get_text()
print(contact)

Error :

selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

How i can run this script in --headless mode ?

Thanks

Sarath C
  • 187
  • 2
  • 10

1 Answers1

0

Finally i fixed by adding

chrome_options.add_argument("--window-size=1920,1080")
chrome_options.add_argument("--start-maximized")
chrome_options.add_argument("--headless")
Sarath C
  • 187
  • 2
  • 10