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

Gemini Live’s screen sharing is now free for Android users Gemini Live’s screen sharing is now free for Android users Technology
Transforming App Development with AI: Series Overview Transforming App Development with AI: Series Overview Technology
Homeowners and California’s Green Lawn Care Law Homeowners and California’s Green Lawn Care Law Technology
What Can Small Businesses Do to Help Prevent a Cyber Attack? – Inner PC Computer Solutions What Can Small Businesses Do to Help Prevent a Cyber Attack? – Inner PC Computer Solutions Technology
Digital twins and transitioning to a greener, safer industrial sector Digital twins and transitioning to a greener, safer industrial sector Technology
HP 14s laptop first impressions. HP 14s laptop first impressions. Technology

Leave a Reply Cancel reply

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

Recent Posts

  • Sister-led social commerce startup Nectar lands $10.6M, reveals more about marketing tech
  • England vs India Test series gets a new name
  • Vietnamese Stop Importing Bitcoin Mining Rigs as Import Ban Looms
  • Apple May Finally Announce Vision Pro VR Controller Support Next Week
  • How to Bring Your Social Media Monetization Strategy to Email

Categories

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

Copyright © 2025 Up To Date Time.

Powered by PressBook Blog WordPress theme