-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

9
  • Which line give you that error ? Is it show_number_btn_xpath = '//span[contains(text(),"Show number")]' ? Commented Jun 14, 2021 at 6:49
  • 1
    @cruisepandey he just trying to gain some points. This is exactly what he asked in his previous question and I answered him there. It's OKay :) Commented Jun 14, 2021 at 7:06
  • @Prophet : Gaining more reputation is a long term time investment here at SO. He would fed up after some time doing this. It's a fair game. Commented Jun 14, 2021 at 7:21
  • not exactly.... Commented Jun 14, 2021 at 7:23
  • 1
    @cruisepandey Sure, but this should be done in fair way Commented Jun 14, 2021 at 7:24

1 Answer 1

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")
Sign up to request clarification or add additional context in comments.

1 Comment

So you just re-asked your previous question and answered here what I have answered you there?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.