Last active
October 17, 2018 12:07
-
-
Save Te-k/32d3f6e7f725846fc0aa925563f4a791 to your computer and use it in GitHub Desktop.
Download information from a paste on pastebin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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