Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import urllib.request
- import random
- from bs4 import BeautifulSoup
- output = open("output_babel.txt", "r+")
- lines = 1
- reqNumber = 1
- while output.readline():
- if(lines % 48 == 0):
- reqNumber += 1
- lines += 1
- while True:
- keyLength = random.randint(1, 3260)
- key = ""
- for i in range(0, keyLength):
- randAscii = random.randint(87, 122)
- if(randAscii < 97):
- randAscii %= 10
- key += str(randAscii)
- else:
- key += chr(randAscii)
- wall = "-w" + str(random.randint(1, 4))
- shelf = "-s" + str(random.randint(1, 5))
- volume = random.randint(1, 32)
- if volume < 10:
- volume = "-v0" + str(volume)
- else:
- volume = "-v" + str(volume)
- page = ":" + str(random.randint(1, 410))
- url = "https://libraryofbabel.info/book.cgi?"+key+wall+shelf+volume+page
- html_page = BeautifulSoup(urllib.request.urlopen(url), "html.parser")
- title = html_page.title.get_text()
- text = html_page.find( "div", {"class":"bookrealign"}).get_text()
- print("#### "+str(reqNumber)+" ####")
- print("Key: "+key)
- print("Title: "+title)
- print("Wall: "+str(wall[2]))
- print("Shelf: "+str(shelf[2]))
- print("Volume: "+str(volume[2])+str(volume[3]))
- print(text)
- outputText = "#### "+str(reqNumber)+" ####"
- outputText += "\nKey: "+key
- outputText += "\nTitle: "+title
- outputText += "\nWall: "+str(wall[2])
- outputText += "\nShelf: "+str(shelf[2])
- outputText += "\nVolume: "+str(volume[2])+str(volume[3])
- outputText += "\n" + text
- if(reqNumber > 1):
- output.write("\n\n")
- output.write(outputText)
- reqNumber += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement