Skip to content

Instantly share code, notes, and snippets.

@javascripto
Created March 5, 2018 02:38
Show Gist options
  • Select an option

  • Save javascripto/646d46eadbde43d1d9209f226c938620 to your computer and use it in GitHub Desktop.

Select an option

Save javascripto/646d46eadbde43d1d9209f226c938620 to your computer and use it in GitHub Desktop.
Web Scraping hipsters.tech inspirado no podcast #82 - Programar sem enxergar
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
# Web Scraping com BeautifulSoup para baixar ultimos 5 podcasts do hipsters.tech
# Inspirado no podcast: Programar sem enxergar - Hipsters #82
# https://hipsters.tech/programar-sem-enxergar-hipsters-82/
import requests
from bs4 import BeautifulSoup
from time import time
from os import system
def catch_audio_link(url):
soup = get_soup(url)
link = soup.find('audio').source['src']
return link[0:link.find('.mp3')+4]
def get_soup(url):
page = requests.get(url).text
return BeautifulSoup(page, 'html.parser')
print('Fazendo scraping na pagina: https://hipsters.tech ...')
inicio = time()
soup = get_soup('https://hipsters.tech')
links = soup.find_all('h1', attrs={'class': 'entry-title'}, limit=5)
urls = list(map(lambda link: link.a['href'], links))
audio_links = list(map(catch_audio_link, urls))
fim = time()
print("Tempo de scraping: {} segundos".format(int(fim - inicio)))
print('Baixando os 5 últimos podcasts...')
print('Pressione Ctrl+C para cancelar')
for mp3 in audio_links:
print("\nBaixando: " + mp3)
system('wget ' + mp3 + ' -q --show-progress')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment