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

Como Instalar duas versão do Python no Linux Como Instalar duas versão do Python no Linux Technology
Apple iPad mini A17 Pro (2024): a premium mini tablet experience that still captivates Apple iPad mini A17 Pro (2024): a premium mini tablet experience that still captivates Technology
Brother DS-640 Portable Scanner Review Brother DS-640 Portable Scanner Review Technology
Best Wi-Fi prices & Internet Service Providers in Kenya Best Wi-Fi prices & Internet Service Providers in Kenya Technology
Oculus quest battery life – Computer Technology Oculus quest battery life – Computer Technology Technology
Smartphone-Blocking Tech Prevents Driver Distraction Crashes Smartphone-Blocking Tech Prevents Driver Distraction Crashes Technology

Leave a Reply Cancel reply

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

Recent Posts

  • India undecided on playing XI, England send strong signal
  • Top 5 Challenges in the Publishing Industry and How to Solve Them
  • Ethereum NFT Sales Skyrocket, Nearing $4K ETH Milestone!
  • The XR Week Peek (2025.07.21): Bytedance may be working on an MR headset, HTC teases a new product, and more!
  • Apple enhances M5 iPad Pro with more cameras, thinner bezels

Categories

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

Copyright © 2025 Up To Date Time.

Powered by PressBook Blog WordPress theme