Bonjour à tous,
J'essaie d'écrire un code pour scraper plusieurs liens en parallèle avec PyQt mais j'ai quelques soucis.
Voici mon code:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import sys
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
 
from PyQt5.QtWebEngineWidgets import QWebEnginePage
 
import time
 
urlb = "https://www.google.fr/"
 
 
class Worker(QRunnable, QWebEnginePage):
    '''
    Worker thread
    '''
    def __init__(self, url):
        super(Worker, self).__init__()
        self.url = url
 
    def _on_load_finished(self):
        print("tfouuu")
        self.html = self.toHtml(self.Callable)
        print('Load finished')
 
    def Callable(self, html_str):
        self.html = html_str
 
    @pyqtSlot()
    def run(self):
        print("a") 
        time.sleep(2)
        print(self.url)
        print("b")
        QWebEnginePage.__init__(self)
        print("c")
        self.html = ''
        self.loadFinished.connect(self._on_load_finished)
        self.load(QUrl(url))
        print("d")
 
class MainWindow(QMainWindow):
 
 
    def __init__(self, *args, **kwargs):
 
        self.threadpool = QThreadPool()
        print("Multithreading with maximum %d threads" % self.threadpool.maxThreadCount())
 
        super(MainWindow, self).__init__(*args, **kwargs)
 
        worker = Worker(urlb)
        worker2 = Worker(urlb)
        self.threadpool.start(worker)
        self.threadpool.start(worker2)
 
 
 
 
app = QApplication([])
window = MainWindow()
app.exec_()
J'ai 2 problèmes:
-Mon code ne cesse de tourner (peut être en raison de l'absence d'un app.quit() mais je ne sais pas trop où le placer)
-Et surtout mon code n'affiche que 'a', 'b', 'c', c'est à dire qu'il n'execute pas les parties connect et load

J'ai beau chercher mais je ne trouve que des discussions proposant de faire ca en séquentiel, mais je voudrais vraiment le faire tourner en parallèle car je ne vois pas ce qui peut poser problème.

Merci pour votre aide !