PDA

View Full Version : Is it possible to login to a site and use QtWebkit



steve38
19th April 2016, 21:14
Hi guys,

I'm not sure if this is the right section for this but I'm certainly a Newbie so here goes. My aim is to log into a website and download a number of web pages as PDF's.
I'm using Python 2.7 and pyqt4 and have found numerous scripts and ways to download web pages as PDF's but none of them seem to allow login and also the download of multiple web pages to PDF's together.
I have a script that uses QtWebkit, takes a url or number of and saves the web page/pages to a local folder as PDF's, as I say this works fine until there is a need to login to a site or handle cookies.
I could do the login and session/cookie handling with 'requests' or 'urllib' and cookielib but then cant load the url's with QtWebkit, I just don't seem to be able to find a way to combine the functionality of login and cookies with the PDF saving.
Or is there a way give login details with QtWebkit.

Cheers
Steve

ChrisW67
19th April 2016, 21:59
You can set the credentials on the QUrl you pass to QWebFrame::load()

Your QWebPage uses a QNetworkAccessManager (which you can retrieve a pointer to) to perform the network activity. QNetworkAccessManager emits a signal authenticationRequired() when it is requested to by the remote site. You could connect that signal to a slot that returns the correct authenticator details.