通过for循环调用类时,PyQt4 QNetworkConfigurationManager(Python)出错

时间:2016-09-20 13:31:39

标签: web-scraping pyqt4 dynamic-websites

我正在尝试使用Pyqt4收集动态网页。我试图循环包含要删除的URL的CSV。但是在遍历循环中的每个记录之后,我得到以下异常,

  

QObject :: connect:无法连接(null):: configurationAdded(QNetworkConfiguration)到QNetworkConfigurationManager :: configurationAdded(QNetworkConfiguration)   QObject :: connect:无法连接(null):: configurationRemoved(QNetworkConfiguration)到QNetworkConfigurationManager :: configurationRemoved(QNetworkConfiguration)   QObject :: connect:无法连接(null):: configurationChanged(QNetworkConfiguration)到QNetworkConfigurationManager :: configurationChanged(QNetworkConfiguration)   QObject :: connect:无法连接(null):: onlineStateChanged(bool)到QNetworkConfigurationManager :: onlineStateChanged(bool)   QObject :: connect:无法连接(null):: configurationUpdateComplete()到QNetworkConfigurationManager :: updateCompleted()   分段错误(核心转储)

读取CSV并呈现网址的代码

import sys  
from PyQt4.QtGui import *  
from PyQt4.QtCore import *  
from PyQt4.QtWebKit import *  
from django.utils.encoding import smart_str, smart_unicode
class Render(QWebPage):  
  def __init__(self, url):  
    #print 'load url init'
    self.app = QApplication(sys.argv)  
    QWebPage.__init__(self)  
    self.loadFinished.connect(self._loadFinished)  
    self.mainFrame().load(QUrl(url))  
    self.app.exec_()  
    #print 'url loaded'
  def _loadFinished(self, result):  
    self.frame = self.mainFrame()  
    #print 'app quit'
    self.app.quit()  
import csv 
with open('Trial1.csv') as csvfile:
   reader = csv.DictReader(csvfile)
   for row in reader:      
      print 'Load Csv'
      url = row['URL']
      r = Render(url)
      html = r.frame.toHtml()
      print 'writ file'
      f = open('Harvest/'+row['ID'] + '.html', 'a')
      f.write(smart_str(html))
      f.close()
      print(row['ID'])

注意:我是Python的新手,这是我在Python中的第一个程序。我通过引用互联网构建了这个代码。请帮我确定发生此异常的位置和原因。提前谢谢!

0 个答案:

没有答案