Dunaevlad
@Dunaevlad

Как избежать ошибки exit code -1073741819 (0xC0000005)?

как исправить данную ошибку? Дело точно в коде, на Ubuntu тоже выдает ошибку, что - то связанную с памятью и рекурсией.

Сам код:
import sys
from PyQt5.QtCore import QEventLoop,QUrl
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWebEngineWidgets import QWebEngineView
from bs4 import BeautifulSoup


class Render(QWebEngineView):
    def __init__(self, url):
        self.html = None
        self.app = QApplication(sys.argv)
        QWebEngineView.__init__(self)
        self.loadFinished.connect(self._loadFinished)
        self.load(QUrl(url))
        while self.html is None:
            self.app.processEvents(QEventLoop.ExcludeUserInputEvents |
                                   QEventLoop.ExcludeSocketNotifiers |
                                   QEventLoop.WaitForMoreEvents)
        self.app.quit()

    def _callable(self, data):
        self.html = data

    def _loadFinished(self, result):
        self.page().toHtml(self._callable)


if __name__ == '__main__':
    print("Collecting data...")

    for p in range(3):

        html = Render(f'https://hh.ru/search/vacancy?area=&fromSearchLine=true&st=searchVacancy&text=&page={p}').html
        # get data from page
        bs4 = BeautifulSoup(html, "lxml")
        for elem in bs4.find_all("div", "vacancy-serp-item"):
            print(elem.find('a', 'bloko-link').text)


Ошибка вылазит после попытки спарсить данные со страницы 2, 1-ю парсит
  • Вопрос задан
  • 589 просмотров
Решения вопроса 1
@cython
PyQt не предполагает, что вы будете создавать QApplication несколько раз. Из-за этого, видимо, и возникает ошибка с памятью, так как где-то может быть обращение к невалидному указателю.
Мне кажется, что для ваших целей лучше подойдёт Selenium, а не PyQt.
import sys
from PyQt5.QtCore import QEventLoop, QUrl
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWebEngineWidgets import QWebEngineView
from bs4 import BeautifulSoup


class Render(QWebEngineView):
    def __init__(self):
        self.html = None
        self.app = QApplication(sys.argv)
        QWebEngineView.__init__(self)
        self.loadFinished.connect(self._loadFinished)

    def _callable(self, data):
        self.html = data

    def _loadFinished(self, result):
        self.page().toHtml(self._callable)

    def get_data(self, url):
        self.html = None
        self.load(QUrl(url))
        while self.html is None:
            self.app.processEvents(QEventLoop.ExcludeUserInputEvents |
                                   QEventLoop.ExcludeSocketNotifiers |
                                   QEventLoop.WaitForMoreEvents)
        return self.html


if __name__ == '__main__':
    print("Collecting data...")
    render = Render()

    for p in range(3):
        html = render.get_data(f'https://hh.ru/search/vacancy?area=&fromSearchLine=true&st=searchVacancy&text=&page={p}')
        # get data from page
        bs4 = BeautifulSoup(html, "lxml")
        for elem in bs4.find_all("div", "vacancy-serp-item"):
            print(elem.find('a', 'bloko-link').text)
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы