@@ -1429,10 +1429,14 @@ def load_html_file(self, html_file, new_page=True):
1429
1429
if len (html_file ) < 6 or not html_file .endswith (".html" ):
1430
1430
raise Exception ('Expecting a ".html" file!' )
1431
1431
abs_path = os .path .abspath ('.' )
1432
- file_path = abs_path + "/%s" % html_file
1433
- f = open (file_path , 'r' )
1434
- html_string = f .read ().strip ()
1435
- f .close ()
1432
+ file_path = None
1433
+ if abs_path in html_file :
1434
+ file_path = html_file
1435
+ else :
1436
+ file_path = abs_path + "/%s" % html_file
1437
+ html_string = None
1438
+ with open (file_path , 'r' ) as f :
1439
+ html_string = f .read ().strip ()
1436
1440
self .load_html_string (html_string , new_page )
1437
1441
1438
1442
def open_html_file (self , html_file ):
@@ -1768,9 +1772,9 @@ def load_cookies(self, name="cookies.txt"):
1768
1772
abs_path = os .path .abspath ('.' )
1769
1773
file_path = abs_path + "/%s" % folder
1770
1774
cookies_file_path = "%s/%s" % (file_path , name )
1771
- f = open ( cookies_file_path , 'r' )
1772
- json_cookies = f . read (). strip ()
1773
- f . close ()
1775
+ json_cookies = None
1776
+ with open ( cookies_file_path , 'r' ) as f :
1777
+ json_cookies = f . read (). strip ()
1774
1778
cookies = json .loads (json_cookies )
1775
1779
for cookie in cookies :
1776
1780
if 'expiry' in cookie :
0 commit comments