Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. How to conutinue
Qt 6.12 LTS is out! See what's new in the release blog

How to conutinue

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
18 Posts 4 Posters 3.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #4

    You are not doing anything with c_url, hence my question what is your actual issue ?

    Keeping the generated urls somewhere as class members ? Using them ?

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    SeaLongHoangS 1 Reply Last reply
    1
    • SGaistS SGaist

      You are not doing anything with c_url, hence my question what is your actual issue ?

      Keeping the generated urls somewhere as class members ? Using them ?

      SeaLongHoangS Offline
      SeaLongHoangS Offline
      SeaLongHoang
      wrote on last edited by SeaLongHoang
      #5

      @SGaist Oh, my bad, I intended to obtain the HTML code of the requested web page from c_url in the same way as the first url did.

      eyllanescE 1 Reply Last reply
      0
      • SeaLongHoangS SeaLongHoang

        @SGaist Oh, my bad, I intended to obtain the HTML code of the requested web page from c_url in the same way as the first url did.

        eyllanescE Offline
        eyllanescE Offline
        eyllanesc
        wrote on last edited by
        #6

        @SeaLongHoang You have to invoke back on request:

        class Manager:
            def __init__(self):
                self.manager.finished.connect(self.handle_response)
        
            @cached_property
            def manager(self):
                return QtNetwork.QNetworkAccessManager()
        
            def start(self):
                self.start_request(
                    QtCore.QUrl(
                        "https://saytruyen.net/truyen-su-tro-lai-cua-phap-su-hac-am-sau-66666-nam.html"
                    )
                )
        
            def start_request(self, url):
                request = QtNetwork.QNetworkRequest(url)
                self.manager.get(request)
        
            def handle_response(self, reply):
                err = reply.error()
                if err == QtNetwork.QNetworkReply.NoError:
                    self.process(reply.readAll().encode("utf-8"))
                else:
                    print("Error occured: ", err)
                    print(reply.errorString())
        
            def process(self, data):
                html = HTML(html=data)
                rs = html.find("#list-chapter a", first=False)
                for i in reversed(rs):
                    url = "https://saytruyen.net/" + i.attrs["href"]
                    self.start_request(QtCore.QUrl(url))
        
        
        def main():
            app = QtCore.QCoreApplication()
        
            manager = Manager()
            manager.start()
        
            app.exec_()
        
        
        if __name__ == "__main__":
            main()
        

        If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

        SeaLongHoangS 1 Reply Last reply
        1
        • eyllanescE eyllanesc

          @SeaLongHoang You have to invoke back on request:

          class Manager:
              def __init__(self):
                  self.manager.finished.connect(self.handle_response)
          
              @cached_property
              def manager(self):
                  return QtNetwork.QNetworkAccessManager()
          
              def start(self):
                  self.start_request(
                      QtCore.QUrl(
                          "https://saytruyen.net/truyen-su-tro-lai-cua-phap-su-hac-am-sau-66666-nam.html"
                      )
                  )
          
              def start_request(self, url):
                  request = QtNetwork.QNetworkRequest(url)
                  self.manager.get(request)
          
              def handle_response(self, reply):
                  err = reply.error()
                  if err == QtNetwork.QNetworkReply.NoError:
                      self.process(reply.readAll().encode("utf-8"))
                  else:
                      print("Error occured: ", err)
                      print(reply.errorString())
          
              def process(self, data):
                  html = HTML(html=data)
                  rs = html.find("#list-chapter a", first=False)
                  for i in reversed(rs):
                      url = "https://saytruyen.net/" + i.attrs["href"]
                      self.start_request(QtCore.QUrl(url))
          
          
          def main():
              app = QtCore.QCoreApplication()
          
              manager = Manager()
              manager.start()
          
              app.exec_()
          
          
          if __name__ == "__main__":
              main()
          
          SeaLongHoangS Offline
          SeaLongHoangS Offline
          SeaLongHoang
          wrote on last edited by
          #7

          @eyllanesc When I execute that code, I discover some bugs.

          Traceback (most recent call last):
            File "c:\Users\ASUS\Videos\LEECH MANGA\test.py", line 40, in <module>
              manager = Manager()
            File "c:\Users\ASUS\Videos\LEECH MANGA\test.py", line 6, in __init__ 
              self.manager.finished.connect(self.handle_response)
          AttributeError: 'function' object has no attribute 'finished'
          
          jsulmJ 1 Reply Last reply
          0
          • SeaLongHoangS SeaLongHoang

            @eyllanesc When I execute that code, I discover some bugs.

            Traceback (most recent call last):
              File "c:\Users\ASUS\Videos\LEECH MANGA\test.py", line 40, in <module>
                manager = Manager()
              File "c:\Users\ASUS\Videos\LEECH MANGA\test.py", line 6, in __init__ 
                self.manager.finished.connect(self.handle_response)
            AttributeError: 'function' object has no attribute 'finished'
            
            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #8

            @SeaLongHoang said in How to conutinue:

            self.manager.finished.connect(self.handle_response)

            Then fix this line...

            self.manager().finished.connect(self.handle_response)
            

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            SeaLongHoangS eyllanescE 2 Replies Last reply
            4
            • jsulmJ jsulm

              @SeaLongHoang said in How to conutinue:

              self.manager.finished.connect(self.handle_response)

              Then fix this line...

              self.manager().finished.connect(self.handle_response)
              
              SeaLongHoangS Offline
              SeaLongHoangS Offline
              SeaLongHoang
              wrote on last edited by SeaLongHoang
              #9

              @jsulm Thank you for your advice, but it is still has a bug. When I run it, it returns this:

              QObject::connect: No such signal QObject::finished(QNetworkReply*)
              
              1 Reply Last reply
              0
              • jsulmJ jsulm

                @SeaLongHoang said in How to conutinue:

                self.manager.finished.connect(self.handle_response)

                Then fix this line...

                self.manager().finished.connect(self.handle_response)
                
                eyllanescE Offline
                eyllanescE Offline
                eyllanesc
                wrote on last edited by
                #10

                @jsulm In my original code I use cached_property so you should not modify it but import it: from functools import cached_property

                If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

                SeaLongHoangS 1 Reply Last reply
                0
                • eyllanescE eyllanesc

                  @jsulm In my original code I use cached_property so you should not modify it but import it: from functools import cached_property

                  SeaLongHoangS Offline
                  SeaLongHoangS Offline
                  SeaLongHoang
                  wrote on last edited by
                  #11

                  @eyllanesc Thank you very much, however I believe you could examine your code more carefully at times, such as this lineself.process(reply.readAll().encode("utf-8")) it must be self.process(str(reply.readAll(), 'utf-8'))

                  jsulmJ 1 Reply Last reply
                  0
                  • SeaLongHoangS SeaLongHoang

                    @eyllanesc Thank you very much, however I believe you could examine your code more carefully at times, such as this lineself.process(reply.readAll().encode("utf-8")) it must be self.process(str(reply.readAll(), 'utf-8'))

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #12

                    @SeaLongHoang said in How to conutinue:

                    however I believe you could examine your code more carefully at times

                    Well, people here are volunteers and don't have to write exact and tested code. You should adjust the code as needed if something is wrong there.

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    SeaLongHoangS 1 Reply Last reply
                    1
                    • jsulmJ jsulm

                      @SeaLongHoang said in How to conutinue:

                      however I believe you could examine your code more carefully at times

                      Well, people here are volunteers and don't have to write exact and tested code. You should adjust the code as needed if something is wrong there.

                      SeaLongHoangS Offline
                      SeaLongHoangS Offline
                      SeaLongHoang
                      wrote on last edited by SeaLongHoang
                      #13

                      @jsulm Okay, I get that, and I appreciate all of your assistance, but I have a little question for you: how can I continue to locate elements from that new request?

                      @eyllanesc said in How to conutinue:

                         self.start_request(QtCore.QUrl(url))
                      
                      jsulmJ 1 Reply Last reply
                      0
                      • SeaLongHoangS SeaLongHoang

                        @jsulm Okay, I get that, and I appreciate all of your assistance, but I have a little question for you: how can I continue to locate elements from that new request?

                        @eyllanesc said in How to conutinue:

                           self.start_request(QtCore.QUrl(url))
                        
                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #14

                        @SeaLongHoang said in How to conutinue:

                        how can I continue to locate elements from that new request?

                        What do you mean by that?
                        If you mean how to handle the response - that is what handle_response() slot does.

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        SeaLongHoangS 1 Reply Last reply
                        0
                        • jsulmJ jsulm

                          @SeaLongHoang said in How to conutinue:

                          how can I continue to locate elements from that new request?

                          What do you mean by that?
                          If you mean how to handle the response - that is what handle_response() slot does.

                          SeaLongHoangS Offline
                          SeaLongHoangS Offline
                          SeaLongHoang
                          wrote on last edited by SeaLongHoang
                          #15

                          @jsulm I mean, if I want to keep getting elements like this from new requests, what should I do? You may view the code below.

                          html = HTML(html=data)
                          rs = html.find("#list-chapter a", first=False)
                          for i in reversed(rs):
                                      url = "https://saytruyen.net/" + i.attrs["href"]
                                      self.start_request(QtCore.QUrl(url))
                          
                          jsulmJ 1 Reply Last reply
                          0
                          • SeaLongHoangS SeaLongHoang

                            @jsulm I mean, if I want to keep getting elements like this from new requests, what should I do? You may view the code below.

                            html = HTML(html=data)
                            rs = html.find("#list-chapter a", first=False)
                            for i in reversed(rs):
                                        url = "https://saytruyen.net/" + i.attrs["href"]
                                        self.start_request(QtCore.QUrl(url))
                            
                            jsulmJ Offline
                            jsulmJ Offline
                            jsulm
                            Lifetime Qt Champion
                            wrote on last edited by
                            #16

                            @SeaLongHoang said in How to conutinue:

                            what should I do?

                            Nothing special. For each request handle_response() will be called which has parameter "reply".

                            https://forum.qt.io/topic/113070/qt-code-of-conduct

                            SeaLongHoangS 1 Reply Last reply
                            1
                            • jsulmJ jsulm

                              @SeaLongHoang said in How to conutinue:

                              what should I do?

                              Nothing special. For each request handle_response() will be called which has parameter "reply".

                              SeaLongHoangS Offline
                              SeaLongHoangS Offline
                              SeaLongHoang
                              wrote on last edited by
                              #17

                              @jsulm What should I replace "...." with in this line html = HTML(html=....) after request to source code HTML from url self.start_request(QtCore.QUrl(url))

                              jsulmJ 1 Reply Last reply
                              0
                              • SeaLongHoangS SeaLongHoang

                                @jsulm What should I replace "...." with in this line html = HTML(html=....) after request to source code HTML from url self.start_request(QtCore.QUrl(url))

                                jsulmJ Offline
                                jsulmJ Offline
                                jsulm
                                Lifetime Qt Champion
                                wrote on last edited by
                                #18

                                @SeaLongHoang Please take a closer look at the code @eyllanesc gave you.

                                https://forum.qt.io/topic/113070/qt-code-of-conduct

                                1 Reply Last reply
                                0

                                • Login

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • Users
                                • Groups
                                • Search
                                • Get Qt
                                • Unsolved