@ -16,7 +16,6 @@ import logging
import datetime
import datetime
import requests
import requests
import threading
import threading
import http . cookiejar
from . message import Message
from . message import Message
from . . import config , text , util , exception , cloudflare
from . . import config , text , util , exception , cloudflare
@ -197,13 +196,12 @@ class Extractor():
self . _update_cookies_dict ( cookies , self . cookiedomain )
self . _update_cookies_dict ( cookies , self . cookiedomain )
elif isinstance ( cookies , str ) :
elif isinstance ( cookies , str ) :
cookiefile = util . expand_path ( cookies )
cookiefile = util . expand_path ( cookies )
cookiejar = http . cookiejar . MozillaCookieJar ( )
try :
try :
cookie jar. load ( cookiefile )
cookie s = util . load_cookiestxt ( cookiefile )
except OSError as exc :
except Exception as exc :
self . log . warning ( " cookies: %s " , exc )
self . log . warning ( " cookies: %s " , exc )
else :
else :
self . _ cookiejar. update ( cookiejar )
self . _ update_cookies( cookies )
self . _cookiefile = cookiefile
self . _cookiefile = cookiefile
else :
else :
self . log . warning (
self . log . warning (
@ -218,11 +216,8 @@ class Extractor():
def _store_cookies ( self ) :
def _store_cookies ( self ) :
""" Store the session ' s cookiejar in a cookies.txt file """
""" Store the session ' s cookiejar in a cookies.txt file """
if self . _cookiefile and self . config ( " cookies-update " , True ) :
if self . _cookiefile and self . config ( " cookies-update " , True ) :
cookiejar = http . cookiejar . MozillaCookieJar ( )
for cookie in self . _cookiejar :
cookiejar . set_cookie ( cookie )
try :
try :
cookiejar. save ( self . _cookiefile )
util . save_cookiestxt ( self . _cookiefile , self . _cookiejar )
except OSError as exc :
except OSError as exc :
self . log . warning ( " cookies: %s " , exc )
self . log . warning ( " cookies: %s " , exc )
@ -491,12 +486,6 @@ def generate_extractors(extractor_data, symtable, classes):
symtable [ Extr . __name__ ] = prev = Extr
symtable [ Extr . __name__ ] = prev = Extr
# Reduce strictness of the expected magic string in cookiejar files.
# (This allows the use of Wget-generated cookiejars without modification)
http . cookiejar . MozillaCookieJar . magic_re = re . compile (
" #( Netscape)? HTTP Cookie File " , re . IGNORECASE )
# Undo automatic pyOpenSSL injection by requests
# Undo automatic pyOpenSSL injection by requests
pyopenssl = config . get ( ( ) , " pyopenssl " , False )
pyopenssl = config . get ( ( ) , " pyopenssl " , False )
if not pyopenssl :
if not pyopenssl :