_s8

Simple parser

_s8
Oct 11th, 2017
494
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. # Simple parser
  2.  
  3. from bs4 import BeautifulSoup
  4. import urllib.request
  5. import urllib.parse
  6.  
  7. def find_pastes(pastebin_link):
  8.     if 'https://pastebin.com/' not in pastebin_link:
  9.         print("Sorry, {} is not a valid link!".format(pastebin_link))
  10.     else:
  11.         try:
  12.             raw_link = pastebin_link.replace('.com', '.com/raw/')
  13.             raw_link = raw_link.replace('raw//', 'raw/')
  14.             page = urllib.request.Request(raw_link)
  15.             page = urllib.request.urlopen(page)
  16.             html_doc = page.read()
  17.             soup = BeautifulSoup(html_doc, 'html.parser')
  18.             print(soup.text)
  19.  
  20.             """
  21.            You could also
  22.            edit it to
  23.            download the
  24.            paste's text,
  25.            if you wanted to.
  26.            """
  27.         except Exception:
  28.             print("There was an error loading your pastebin.")
Advertisement
Add Comment
Please, Sign In to add comment