You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importredisimportbrowscapfrombrowscap.cache.redisimportRedisCacheua="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36"redis_cache=redis.Redis(db=5)
bc=browscap.Browscap(cache=RedisCache(redis_cache))
browser=bc.get_browser(ua)
Detect browser with asyncio
frompprintimportpprintimportasyncioimportasyncio_redisfrombrowscap.aioimportBrowscapAsyncfrombrowscap.aio.cache.redisimportRedisPoolAioCacheloop=asyncio.get_event_loop()
@asyncio.coroutinedefget_browser():
ua="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36"redis_cache=awaitaioredis.create_pool(('localhost', 6379), minsize=5, maxsize=100)
bc=BrowscapAsync(cache=RedisPoolAioCache(redis_cache))
browser=yieldfrombc.get_browser(ua)
cache.close_connection()
returnbrowserif__name__=='__main__':
loop=asyncio.get_event_loop()
browser=loop.run_until_complete(get_browser())
pprint(browser)