Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
from bs4 import BeautifulSoup
import requests
# Trying to open a random wikipedia article
# Special:Random opens random articles
res = requests.get("")
# pip install htmlparser
wiki = BeautifulSoup(res.text, "html.parser")
r = open("random_wiki.txt", "w+", encoding='utf-8')
# Adding the heading to the text file
heading = wiki.find("h1").text
r.write(heading + "\n")
for i in"p"):
# Optional Printing of text
# print(i.getText())
print("File Saved as random_wiki.txt")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment