Ejemplo n.º 1
0
    def __init__(self):
        super().__init__()
        proxy = QNetworkProxy()
        proxy.setType(QNetworkProxy.HttpProxy)
        proxy.setHostName("109.173.124.250")
        proxy.setPort(7793)
        QNetworkProxy.setApplicationProxy(proxy)
        try:
            print("1")
            ua = UserAgent()
            ua.update()
            useragent = ua.random
        except FakeUserAgentError:
            print("2")
            useragent = "Mozilla / 5.0 (Windows NT 10.0; Win64; x64) AppleWebKit / 537.36 (KHTML, как Gecko) Chrome / " \
                        "72.0.3626.121 Safari / 537.36"

        profile = QWebEngineProfile()
        profile.setHttpUserAgent(useragent)
        page = QWebEnginePage(profile)
        page.setUrl(QUrl("https://www.instagram.com/"))
        self.setPage(page)
        self.page().proxyAuthenticationRequired.connect(
            self.handle_proxy_auth_req)

        self.imit_peop = threading.Thread(target=self.imitation_people,
                                          args=())
        self._timer = QTimer()
        self.loadFinished.connect(self.startTimer)
        self._timer.timeout.connect(self.start_thread_imitation)
Ejemplo n.º 2
0
    def __init__(self, settings=None):
        super(Py2WebBrowser, self).__init__()
        self.pwb = QWebEngineView()
        self.pwb.setAttribute(Qt.WA_DeleteOnClose, True)

        if settings is not None:
            self.bconf = settings
        else:
            self.bconf = BaseConfig()

        self.raw_cookies = []
        self.cookie_list = []

        self.req_obj = QWebEngineHttpRequest()

        profile = QWebEngineProfile("pyweb", self.pwb)
        profile.setHttpUserAgent(random.choice(self.bconf.USER_AGENT_LIST))
        cookie_store = profile.cookieStore()

        cookie_store.cookieAdded.connect(self._on_cookie)

        wp = QWebEnginePage(profile, self.pwb)
        self.pwb.setPage(wp)

        self._settings()
        self.pwb.show()
class JWebView(QWebEngineView):
    """ #### Imports: from JAK.WebEngine import JWebView """
    def __init__(self,
                 title="",
                 icon="",
                 web_contents="",
                 debug=False,
                 transparent=False,
                 online=False,
                 url_rules="",
                 cookies_path="",
                 user_agent="",
                 custom_css="",
                 custom_js=""):
        """
        * :param title:str
        * :param icon:str
        * :param web_contents:str
        * :param debug:bool
        * :param transparent:bool
        * :param online:bool
        * :param disable_gpu:bool
        * :param url_rules:dict
        * :param cookies_path:str
        * :param user_agent:str
        * :param custom_css:str
        * :param custom_js:str
        * :param toolbar:dict
        """
        super(JWebView, self).__init__()
        self.setAttribute(Qt.WA_DeleteOnClose, True)
        self.debug = debug
        self.online = online
        self.home = web_contents
        self.profile = QWebEngineProfile().defaultProfile()
        self.webpage = JWebPage(icon, debug, online, cookies_path, url_rules)
        self.setPage(self.webpage)
        self.page().loadFinished.connect(self._page_load_finish)
        if custom_css:
            # Check for custom CSS
            self.custom_css = custom_css
            print("Custom CSS detected")

        if custom_js:
            # Check for custom JavaScript
            self.custom_js = custom_js
            print("Custom JavaScript detected")

        if url_rules:
            # Check for URL rules
            try:
                self.block_rules = url_rules["block"]
            except KeyError:
                self.block_rules = ""
            finally:
                self.interceptor = Interceptor(debug, self.block_rules)
        else:
            self.interceptor = Interceptor(debug)

        if user_agent:
            # Set user agent
            self.user_agent = user_agent
            self.profile.setHttpUserAgent(user_agent)

        if self.debug:
            # TODO implement webinspector
            self.settings().setAttribute(QWebEngineSettings.XSSAuditingEnabled,
                                         True)
        else:
            self.setContextMenuPolicy(Qt.PreventContextMenu)

        if transparent:
            # Activates background transparency
            self.setAttribute(Qt.WA_TranslucentBackground)
            self.page().setBackgroundColor(Qt.transparent)
            self.setStyleSheet("background:transparent;")
            print(
                "Transparency detected, make sure you set [ body {background:transparent;} ]"
            )

        settings = self.settings()
        # * Set Engine options
        # * TODO: allow to set settings per application by passing a list
        settings.setAttribute(QWebEngineSettings.JavascriptCanPaste, True)
        settings.setAttribute(QWebEngineSettings.PlaybackRequiresUserGesture,
                              False)
        settings.setAttribute(QWebEngineSettings.FullScreenSupportEnabled,
                              True)
        settings.setAttribute(
            QWebEngineSettings.AllowWindowActivationFromJavaScript, True)
        settings.setAttribute(
            QWebEngineSettings.LocalContentCanAccessRemoteUrls, True)
        settings.setAttribute(QWebEngineSettings.JavascriptCanAccessClipboard,
                              True)
        settings.setAttribute(QWebEngineSettings.SpatialNavigationEnabled,
                              True)
        settings.setAttribute(QWebEngineSettings.TouchIconsEnabled, True)
        settings.setAttribute(QWebEngineSettings.FocusOnNavigationEnabled,
                              True)
        if online:
            settings.setAttribute(QWebEngineSettings.DnsPrefetchEnabled, True)
            print("Engine online (IPC) Disabled")
            self.page().profile().downloadRequested.connect(
                self._download_requested)

            # Set persistent cookies
            self.profile.setPersistentCookiesPolicy(
                QWebEngineProfile.ForcePersistentCookies)

            # set cookies on user folder
            if cookies_path:
                # allow specific path per application.
                _cookies_path = f"{os.getenv('HOME')}/.jak/{cookies_path}"
            else:
                # use separate cookies database per application
                title = title.lower().replace(" ", "-")
                _cookies_path = f"{os.getenv('HOME')}/.jak/{title}"

            self.profile.setPersistentStoragePath(_cookies_path)
            print(f"Cookies PATH:{_cookies_path}")
        else:
            print("Engine interprocess communication (IPC) up and running:")
            #self.profile.setHttpCacheType(self.profile.MemoryHttpCache)

        self.profile.setRequestInterceptor(self.interceptor)
        print(self.profile.httpUserAgent())
        validate_url(self, web_contents)

    def _page_load_finish(self) -> None:
        result = time.localtime(time.time())
        print(f"Document Ready in: {result.tm_sec} seconds")
        try:
            if self.custom_css:
                print("Custom CSS loaded")
                JavaScript.css(self, self.custom_css)
        except AttributeError:
            pass

        try:
            if self.custom_js:
                print("Custom JavaScript loaded")
                JavaScript.send(self, self.custom_js)
        except AttributeError:
            pass

    def _download_requested(self, download_item) -> None:
        """
        * If a download is requested call a save file dialog
        * :param download_item: file to be downloaded
        """
        from PySide2.QtWidgets import QFileDialog
        self.download_item = download_item
        dialog = QFileDialog(self)
        path = dialog.getSaveFileName(dialog, "Save File",
                                      download_item.path())

        if path[0]:
            print(path)
            download_item.setPath(path[0])
            print(f"downloading file to:( {download_item.path()} )")
            download_item.accept()
            download_item.finished.connect(self._download_finished)

        else:
            print("Download canceled")

    def _download_finished(self) -> None:
        """
        Goes to previous page and pops an alert informing the user that the download is finish and were to find it
        """
        file_path = self.download_item.path()
        msg = f"File Downloaded to: {file_path}"

        try:
            from Widgets import InfoDialog
        except ImportError:
            from JAK.Widgets import InfoDialog
        InfoDialog(self, "Download Complete", msg)
        if self.online:
            self.back()

    def navigate_home(self) -> None:
        """
        Goes back to original application url
        """
        self.load(self.home)
Ejemplo n.º 4
0
     print("2")
     userAgent = "Mozilla / 5.0 (Windows NT 10.0; Win64; x64) AppleWebKit / 537.36 (KHTML, как Gecko) Chrome / " \
                 "72.0.3626.121 Safari / 537.36"
 app = QApplication(sys.argv)
 proxy = QNetworkProxy()
 proxy.setType(QNetworkProxy.HttpProxy)
 proxy.setHostName("109.173.124.250")
 proxy.setPort(7793)
 QNetworkProxy.setApplicationProxy(proxy)
 grid = QGridLayout()
 # browser = QWebEngineView()
 browser = Browser()
 # url_input = UrlInput(browser)
 list_view = QListView()
 list_view.setFixedWidth(300)
 #  interceptor = WebEngineUrlRequestInterceptor()
 profile = QWebEngineProfile()
 profile.setHttpUserAgent(userAgent)
 page = MyWebEnginePage(profile, browser)
 page.setUrl(QUrl("https://www.instagram.com/"))
 # page.setUrl(QUrl("https://2ip.ru"))
 browser.setPage(page)
 page_proxy = browser.page()
 page_proxy.proxyAuthenticationRequired.connect(handleProxyAuthReq)
 grid.addWidget(list_view, 0, 1)
 grid.addWidget(browser, 0, 2)
 main_frame = QWidget()
 main_frame.setMinimumSize(800, 600)
 main_frame.setLayout(grid)
 main_frame.show()
 sys.exit(app.exec_())