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

Some Advantages of Working Remotely – Inner PC Computer Solutions Some Advantages of Working Remotely – Inner PC Computer Solutions Technology
How to create a YouTube video chapters’ timings generator using Gemini over Vertex AI How to create a YouTube video chapters’ timings generator using Gemini over Vertex AI Technology
DeepSeek & the Energy Question No One is Asking DeepSeek & the Energy Question No One is Asking Technology
Learning from the Jaguar rebrand campaign Learning from the Jaguar rebrand campaign Technology
My 2024 Black Friday Sale Picks My 2024 Black Friday Sale Picks Technology
Opposition parties speak out on GE2025’s boundary changes Opposition parties speak out on GE2025’s boundary changes Technology

Leave a Reply Cancel reply

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

Recent Posts

  • 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
  • Pacquiao says he’s going to rumble some more

Categories

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

Copyright © 2025 Up To Date Time.

Powered by PressBook Blog WordPress theme