mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Make user agent consistant. Remove debugging code.
This commit is contained in:
parent
5d92612f2e
commit
3883a1d6a2
@ -240,6 +240,8 @@ def get_parsed_proxy(typ='http', debug=True):
|
||||
prints('Using http proxy', str(ans))
|
||||
return ans
|
||||
|
||||
USER_AGENT = 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101210 Gentoo Firefox/3.6.13'
|
||||
USER_AGENT_MOBILE = 'Mozilla/5.0 (Windows; U; Windows CE 5.1; rv:1.8.1a3) Gecko/20060610 Minimo/0.016'
|
||||
|
||||
def browser(honor_time=True, max_time=2, mobile_browser=False, user_agent=None):
|
||||
'''
|
||||
@ -254,8 +256,7 @@ def browser(honor_time=True, max_time=2, mobile_browser=False, user_agent=None):
|
||||
opener.set_handle_refresh(True, max_time=max_time, honor_time=honor_time)
|
||||
opener.set_handle_robots(False)
|
||||
if user_agent is None:
|
||||
user_agent = ' Mozilla/5.0 (Windows; U; Windows CE 5.1; rv:1.8.1a3) Gecko/20060610 Minimo/0.016' if mobile_browser else \
|
||||
'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101210 Gentoo Firefox/3.6.13'
|
||||
user_agent = USER_AGENT_MOBILE if mobile_browser else USER_AGENT
|
||||
opener.addheaders = [('User-agent', user_agent)]
|
||||
http_proxy = get_proxies().get('http', None)
|
||||
if http_proxy:
|
||||
|
@ -8,19 +8,20 @@ from cookielib import Cookie, CookieJar
|
||||
|
||||
from PyQt4.Qt import QWebView, QWebPage, QNetworkCookieJar, QNetworkRequest, QString
|
||||
|
||||
from calibre import USER_AGENT
|
||||
|
||||
class NPWebView(QWebView):
|
||||
|
||||
def __init__(self, *args):
|
||||
QWebView.__init__(self, *args)
|
||||
self.gui = None
|
||||
|
||||
#self.setPage(NPWebPage())
|
||||
self.setPage(NPWebPage())
|
||||
self.page().networkAccessManager().setCookieJar(QNetworkCookieJar())
|
||||
self.page().setForwardUnsupportedContent(True)
|
||||
self.page().unsupportedContent.connect(self.start_download)
|
||||
self.page().downloadRequested.connect(self.start_download)
|
||||
self.page().networkAccessManager().sslErrors.connect(self.ignore_ssl_errors)
|
||||
#self.page().networkAccessManager().finished.connect(self.fin)
|
||||
|
||||
def createWindow(self, type):
|
||||
if type == QWebPage.WebBrowserWindow:
|
||||
@ -33,7 +34,6 @@ class NPWebView(QWebView):
|
||||
|
||||
def start_download(self, request):
|
||||
if not self.gui:
|
||||
print 'no gui'
|
||||
return
|
||||
|
||||
url = unicode(request.url().toString())
|
||||
@ -41,13 +41,7 @@ class NPWebView(QWebView):
|
||||
|
||||
def ignore_ssl_errors(self, reply, errors):
|
||||
reply.ignoreSslErrors(errors)
|
||||
|
||||
def fin(self, reply):
|
||||
if reply.error():
|
||||
print 'error'
|
||||
print reply.error()
|
||||
#print reply.attribute(QNetworkRequest.HttpStatusCodeAttribute).toInt()
|
||||
|
||||
|
||||
def get_cookies(self):
|
||||
cj = CookieJar()
|
||||
|
||||
@ -99,4 +93,4 @@ class NPWebView(QWebView):
|
||||
class NPWebPage(QWebPage):
|
||||
|
||||
def userAgentForUrl(self, url):
|
||||
return 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_6; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.102 Safari/534.13'
|
||||
return USER_AGENT
|
||||
|
Loading…
x
Reference in New Issue
Block a user