Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

168
Visualizações
Best way to get html text element on website and copy it to clipboard?

I constantly need to copy some text data from the same website. Copying it myself is tedious and what I would love to have is: When I enter that website, and this particular element (specified with XPath) has some text in it (it's not blank) then the script gets Text from this element and copies it to my clipboard.

It would be great if it would work in my Chrome browser. Is it something I could achieve with Python and Selenium for example?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If you are just web scrapping then you really don't need selenium unless you need to input something or can't get there with just the URL. Just get the HTML and extract what you need.

import pyperclip
import time
from bs4 import BeautifulSoup
import requests

def get_page_html(url):
    headers = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36"}
    page = requests.get(url, headers=headers)
    return page.content

def parse_html(url):
    page_contents = get_page_html(url)
    soup = BeautifulSoup(page_contents, 'html.parser')
    divs = soup.find("div", {"class": "fulfillment-fulfillment-summary"})
    return divs.encode_contents()

pyperclip.copy(parse_html(<URL>))
s = pyperclip.paste()#If needed
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda