Hey Guys, I recently ran into a problem while playing with Python. The output on the console was displaying the output of a previous code that I had modified. I was playing around PyQt4 to PyQt5 conversion of Sentdex’s PyQt4 YouTube tutorial right here. Everythng went fine until I tried to print the entire page on the console..See the tragic buggy code below:
import bs4 as bs
import sys
import urllib.request
from PyQt5.QtWebEngineWidgets import QWebEnginePage
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import QUrl
class Page(QWebEnginePage):
def __init__(self, url):
self.app = QApplication(sys.argv)
QWebEnginePage.__init__(self)
self.html = ''
self.loadFinished.connect(self._on_load_finished)
self.load(QUrl(url))
self.app.exec_()
def _on_load_finished(self):
self.html = self.toHtml(self.Callable)
print('Load finished')
def Callable(self, html_str):
self.html = html_str
self.app.quit()
def main():
page = Page('https://pythonprogramming.net/parsememcparseface/')
soup = bs.BeautifulSoup(page.html, 'html.parser')
js_test = soup.find('p', class_='jstest')
print js_test.text
#print (soup) # DO NOT DO THIS...This may kill your buffer...Commented it off for your safety
if __name__ == '__main__': main()
See the code section print (soup). I think this created the problem.
Now when I ran another code be it as simple as print(“Hello”) on VS code, the output I got was :
Load finished
Look at you shinin!
Press any key to continue . . .
The uniqueness of this problem was that I only faced this problem on my VS Code IDE only. Execution on direct Anaconda console did not show this issue.
I searched the entire web, but did not find any solution.
I tried to reboot. Tried to flush the buffer. Nothing helped.
Finally, out of desperation, I went on a deletion spree. I manually went inside the temp files in C:\Users\xxx\AppData\Local and started a deletion rampage…removed many files and folder remotely related to python,vscode and conda.
This gave an error warning the first time I executed my program again…then on subsequent run…the issue was resolved…my python is back to its normal self again…
I was surprised that I was not able to find any solution on the net for this. This inspired me to start my own blog to record the problems I face, especially as a noob in Python.
Hope this blog helps others like me.