11#!/usr/bin/env python3
22
33import logging
4- import requests
54import datetime
5+ import requests
6+ import bs4
67from urllib .parse import urljoin
7- from mechanicalsoup import Browser
8- from bs4 import BeautifulSoup
98from pycaching .cache import Cache , Type , Size
109from pycaching .log import Log , Type as LogType
1110from pycaching .geo import Point
@@ -25,7 +24,7 @@ class Geocaching(object):
2524
2625 def __init__ (self ):
2726 self ._logged_in = False
28- self ._browser = Browser ()
27+ self ._session = requests . Session ()
2928
3029 def _request (self , url , * , expect = "soup" , method = "GET" , login_check = True , ** kwargs ):
3130 # check login unless explicitly turned off
@@ -35,12 +34,12 @@ def _request(self, url, *, expect="soup", method="GET", login_check=True, **kwar
3534 url = url if "//" in url else urljoin (self ._baseurl , url )
3635
3736 try :
38- res = self ._browser .request (method , url , ** kwargs )
37+ res = self ._session .request (method , url , ** kwargs )
3938 res .raise_for_status ()
4039
4140 # return bs4.BeautifulSoup, JSON dict or raw requests.Response
4241 if expect == "soup" :
43- return res .soup
42+ return bs4 . BeautifulSoup ( res .text , "html.parser" )
4443 elif expect == "json" :
4544 return res .json ()
4645 elif expect == "raw" :
@@ -99,17 +98,17 @@ def login(self, username, password):
9998 def logout (self ):
10099 """Logs out the user.
101100
102- Logs out the user by creating new browser ."""
101+ Logs out the user by creating new session ."""
103102
104103 logging .info ("Logging out." )
105104 self ._logged_in = False
106- self ._browser = Browser ()
105+ self ._session = requests . Session ()
107106
108107 def get_logged_user (self , login_page = None ):
109108 """Returns the name of curently logged user or None, if no user is logged in."""
110109
111110 login_page = login_page or self ._request (self ._urls ["login_page" ], login_check = False )
112- assert isinstance (login_page , BeautifulSoup )
111+ assert isinstance (login_page , bs4 . BeautifulSoup )
113112
114113 logging .debug ("Checking for already logged user." )
115114 try :
@@ -193,7 +192,7 @@ def _search_get_page(self, point, start_index):
193192 "originTreatment" : 0
194193 }, expect = "json" )
195194
196- return BeautifulSoup (res ["HtmlString" ].strip ())
195+ return bs4 . BeautifulSoup (res ["HtmlString" ].strip (), "html.parser" )
197196
198197 def search_quick (self , area , * , strict = False , zoom = None ):
199198 logging .info ("Searching quick in {}" .format (area ))
@@ -228,7 +227,8 @@ def post_log(self, wp, text, type=LogType.found_it, date=datetime.date.today()):
228227 l = Log (type = type , text = text , visited = date )
229228 self .get_cache (wp ).post_log (l )
230229
231- # ensure backwards compatibility -----------------------------------------
230+ # ensure backwards compatibility ------------------------------------------
231+ # deprecated methods will be removed in next version!
232232
233233 @deprecated
234234 def load_cache (self , wp ):
0 commit comments