Advertisement
Koragg

Show Wiki Text [Python 2.7 & 3.6]

Jun 13th, 2018
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | None | 0 0
  1. import wx, wx.html, requests, warnings
  2. from bs4 import BeautifulSoup
  3.  
  4. class Test(wx.Frame):
  5.     def __init__(self, parent, id):
  6.         wx.Frame.__init__(self, parent, id, "Test App 2", (800, 800))
  7.         warnings.filterwarnings("ignore", category = UserWarning, module = "bs4")
  8.         self.panel = wx.Panel(self)
  9.         self.panel.SetBackgroundColour("#FFFFFF")
  10.         self.Centre()
  11.         self.html = wx.html.HtmlWindow(self, pos = (0, 0), size = (700, 700))
  12.         #show text contents of Wikipedia page
  13.         self.URL = "https://en.wikipedia.org/wiki/Selena_Gomez"
  14.         self.respond = requests.get(self.URL)
  15.         self.soup = BeautifulSoup(self.respond.text)
  16.         self.paragraphs = self.soup.find_all("p")
  17.         self.text = ""
  18.         for i in self.paragraphs:
  19.             self.text = self.text + str(i.text.encode("utf8"))
  20.         with open("text.html", "w") as text:
  21.             text.write(self.text)
  22.         self.html.LoadPage("text.html")
  23.  
  24. def main():
  25.     app = wx.App()
  26.     frame = Test(None, -1)
  27.     frame.Show()
  28.     app.MainLoop()
  29.  
  30. if __name__ == "__main__":
  31.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement