示例#1
0
def crawlSingleLocation(id):
    url = 'https://www.geocaching.com/geocache/' + id
    opener = getURLOpener()

    with opener.open(url) as response:
        bs = soup(response.read().decode('utf-8'), 'lxml')
        userTokenIndex = int(str(bs).find("userToken = '") + 13)
        userToken = str(bs)[userTokenIndex : userTokenIndex + 167]

        cache = Cache()
        cache.id = id
        try:
            cache.name = bs.find(id="ctl00_ContentBody_CacheName").string
            cache.difficulty = bs.find(id="ctl00_ContentBody_uxLegendScale").img['alt'].split()[0]
            cache.terrain = bs.find(id="ctl00_ContentBody_Localize12").img['alt'].split()[0]
            cache.size = bs.find(id="ctl00_ContentBody_size").img['alt'].split()[1]
            lat, lon = splitLatLon(bs.find(id="uxLatLon").string)
            cache.lat = lat
            cache.lon = lon
            cache.creator = bs.find(id="ctl00_ContentBody_mcd1").a.string.split(',')[0]
        except:
            print("Error parsing fields of cache with ID {}".format(id))

        try:
            getUsers(userToken, cache)
        except:
            print("Error parsing users of cache with ID {}".format(id))
示例#2
0
def crawlSingleLocation(id):
    cache = Cache()
    cache.id = id
    cache.name = id + "name"
    cache.difficulty = 2
    cache.terrain = 3
    cache.size = 2
    getUsers(cache)