Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2016
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. #-*- coding: utf-8 -*-
  4. from bs4 import BeautifulSoup
  5. import urllib.request
  6. import os, random, re
  7.  
  8. def removeEmptyLines(source_string):
  9.     string_array = source_string.splitlines()
  10.     new_string = ""
  11.     for line in string_array:
  12.         if '<' in line:
  13.            
  14.             new_string += line.replace("\t", "") + "\n"
  15.     return new_string[:-1]
  16.  
  17. def getRandomBashText():
  18.     resp = urllib.request.urlopen("http://bash.org.pl/random/")
  19.     soup = BeautifulSoup(resp, from_encoding=resp.info().get_param('charset'))
  20.  
  21.     for div in soup.find_all('div'):
  22.         if "post-body" in str(div.get('class')):
  23.             print(removeEmptyLines(div.get_text()))
  24.    
  25.  
  26. getRandomBashText()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement