Skip to content
Up To Date Time

Up To Date Time

  • Home
  • Sports
  • cryptocurrency
  • Technology
  • Virtual Reality
  • Education Law
  • More
    • About Us
    • Contact Us
    • Disclaimer
    • Privacy Policy
    • Terms and Conditions
  • Toggle search form
Selenium com Linux sem interface

Selenium com Linux sem interface

Posted on December 8, 2024 By rehan.rafique No Comments on Selenium com Linux sem interface

Como criar um script que acessa uma página web a partir de um servidor linux sem interface

Vamos aprender como configura um navegador Chrome em modo sem interface gráfica. Acessar um site qualquer, obter e exibe o título da página no console. 

Primeiramente, certifique-se de ter o navegador Chrome instalado em sua máquina. Utilize do comandos abaixo:

[wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb]

[sudo dpkg -i google-chrome-stable_current_amd64.deb]

[sudo apt-get install -f]

[google-chrome –version]

O código em python abaixo utiliza o Selenium para automação de navegação em navegadores. Ele configura o navegador Chrome para executar tarefas automaticamente em modo headless (sem interface gráfica).

[from selenium import webdriver

from selenium.webdriver.chrome.service import Service

from webdriver_manager.chrome import ChromeDriverManager

def main():

    browserOptions = webdriver.ChromeOptions()

    browserOptions.add_argument(‘–no-sandbox’)

    browserOptions.add_argument(“–headless”)

    browserOptions.add_argument(“–window-size=1280,720”)

    browserOptions.add_argument(“–disable-gpu”)

    browserOptions.add_argument(‘–disable-dev-shm-usage’)

    browser = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=browserOptions)

    url = “https://limontec.com”

    browser.get(url)

    print(f“Page title: {browser.title}“)

if __name__ == “__main__”:

    main()]

Antes de executar o código acima, instale as dependências necessárias com o comando:

[pip install selenium]

[pip install webdriver_manager]

Importações:

  • webdriver: Usado para interagir com navegadores.
  • Service: Facilita a configuração do driver para o navegador Chrome.
  • ChromeDriverManager: Gerencia automaticamente o download e a configuração do ChromeDriver, eliminando a necessidade de configuração manual.

Opções adicionadas ao navegador para funcionar adequadamente em um ambiente de servidor:

  • –no-sandbox: Desabilita o sandboxing para evitar restrições de segurança.
  • –headless: Executa o navegador em modo sem interface gráfica.
  • –window-size=1280,720: Define o tamanho da janela do navegador..
  • –disable-gpu: Desativa o uso de GPU para renderização.
  • –disable-dev-shm-usage: Reduz problemas de memória compartilhada em sistemas Linux.

Technology

Post navigation

Previous Post: Trauma-Informed Teaching in Special Education
Next Post: Vive Focus Vision and Viverse hands-on: two solutions for businesses

More Related Articles

Reacher Season 3 Release Date Is Out! Will Reacher Find Love This Season? Reacher Season 3 Release Date Is Out! Will Reacher Find Love This Season? Technology
The Middle East Has Entered the AI Group Chat The Middle East Has Entered the AI Group Chat Technology
I’ve stopped caring about OS updates, but Android skins are back in fashion I’ve stopped caring about OS updates, but Android skins are back in fashion Technology
How to Future-Proof Your Career in the Age of Technology How to Future-Proof Your Career in the Age of Technology Technology
Cloud Gateway Max: A Solid Non-Wi-Fi Router Cloud Gateway Max: A Solid Non-Wi-Fi Router Technology
The Trump Team: Why Entrepreneurs, Businessmen, and Celebrities Are Bad Politicians The Trump Team: Why Entrepreneurs, Businessmen, and Celebrities Are Bad Politicians Technology

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • How to go from a prompt to a geo-location guessing app in minutes
  • Coresky Airdrop Guide | How To Be Eligible?
  • My interview with Play For Dream about their headset, Android XR, enterprise licensing, China, and more!
  • Sister-led social commerce startup Nectar lands $10.6M, reveals more about marketing tech
  • England vs India Test series gets a new name

Categories

  • cryptocurrency
  • Education Law
  • Sports
  • Technology
  • Virtual Reality

Copyright © 2025 Up To Date Time.

Powered by PressBook Blog WordPress theme