Skip to content

Instantly share code, notes, and snippets.

@Te-k
Last active October 17, 2018 12:07
Show Gist options
  • Save Te-k/32d3f6e7f725846fc0aa925563f4a791 to your computer and use it in GitHub Desktop.
Save Te-k/32d3f6e7f725846fc0aa925563f4a791 to your computer and use it in GitHub Desktop.
Download information from a paste on pastebin
import requests
from bs4 import BeautifulSoup
def get_info(key):
# Returns the date and raw data
if key.startswith('http'):
r = requests.get(key)
else:
r = requests.get('https://pastebin.com/' + key)
soup = BeautifulSoup(r.text, 'html.parser')
metadataline = soup.find('div', class_='paste_box_line2')
if metadataline.find('a') is None:
user = 'guest'
else:
user = metadataline.find('a').text
return {
'date': parse(
metadataline.find('span').attrs['title'],
tzinfos = {'CDT': 'America/Mexico_City'}
),
'user': user,
'data': soup.find(id='paste_code').text
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment