Python segment error using pyqt4

I wrote a code snippet to clear the web, which actually works with it with a single URL, but as soon as I put more than 2 ursl in .txt, it tells me "Segmentation Error". I do not know where the problem is. Any help would be appreciated.

import sys
import time
import gc
from bs4 import BeautifulSoup
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4.QtWebKit import * 


class Render(QWebPage):
    def __init__(self, url):
        self.app = QApplication(sys.argv)
        QWebPage.__init__(self)
        self.loadFinished.connect(self._loadFinished)
        self.mainFrame().load(QUrl(url))
        self.app.exec_()

    def _loadFinished(self, result):
        self.frame = self.mainFrame()
        #self.deleteLater()
        self.app.quit()

with open('/blah/blah/blah/blah/blah.txt') as f:
    urls = f.read().splitlines()

    for i in urls:
        r = Render(i)
        soup = BeautifulSoup(unicode(r.frame.toHtml()))
        summary = soup.find('div',{'style' : 'padding-top:10px;'})
        tables = summary.find('tbody')
        count = 0
        print 
        for row in tables.findAll('tr'):
            for cell in row.findAll('td'):
                data = cell.getText()
                if (count < 15):
                    data = data + ';'
                    print data, 
                count += 1
                if (count==16):
                    print data
                    count = 0       

Well, this is the code. I get 2 iterations of the loop loop before it tells me that the segmentation error ... :( In other words, I get to clear 2 url's of 6 that txt has.

Thanks in advance for your help

+4
source share
1 answer

. Python ( ). BeautifulSoup:

for _ in range(3):
    r = Render('google.com')

, Render , :

for _ in range(3):
    r = Render('google.com')
    del r

, , PyQt . PyQt, , . , , , .

, , , , , QApplication URL-. , .

+2

Source: https://habr.com/ru/post/1615754/


All Articles