0

I am testing my website to flood its analytic api calls. As my site uses local storage to identify a client, I need to access local storage.

I can access cookies in python using this code:

import cookielib
import urllib2

cookies = cookielib.LWPCookieJar()
handlers = [
    urllib2.HTTPHandler(),
    urllib2.HTTPSHandler(),
    urllib2.HTTPCookieProcessor(cookies)
    ]
opener = urllib2.build_opener(*handlers)

def fetch(uri):
    req = urllib2.Request(uri)
    return opener.open(req)

def dump():
    for cookie in cookies:
        print cookie.name, cookie.value

uri = 'http://localhost:3000'
res = fetch(uri)
dump()

res = fetch(uri)
dump()

# save cookies to disk. you can load them with cookies.load() as well.
cookies.save('mycookies.txt')

How do I access Local storage data in python?

Aditya Chaudhary
  • 303
  • 1
  • 4
  • 11

2 Answers2

1

Local storage is specific to browser.

Local Storage is a way to store persistent data using JavaScript. It should be used only with HTML5 compatible web browser. Local storage - according to stack overflow tag definition

To access Local storage in python, a HTML5 compatible browser's python API is required.

Community
  • 1
  • 1
Aditya Chaudhary
  • 303
  • 1
  • 4
  • 11
  • 1
    the only way to access local storage is with JavaScript in the browser. So you need a python API for javascript. – Daniel Jun 17 '15 at 14:57
0

costales came up with a solution for Chrome, here:

How to read/modify a local file of HTML5 Local Storage from Python?

It makes use of the fact that Chrome and Opera use "SQLite format 3" for Web Storage (a/k/a Local Storage, or DOM Storage). Under Windows 10 Chrome currently keeps its Web Storage files in this folder:

"%LOCALAPPDATA%\Google\Chrome\User Data\Default\Local Storage\"

Opera should be similar. (Old Opera used XML files, but recent versions of Opera are basically forks of Chrome / Chromium.)

Firefox is similar, except that it appears that Firefox uses one great big SQLite database for all Web Storage for all web pages; see Hugh Lee's and Kevin Hakanson's answers here:

Where does Firefox store javascript/HTML localStorage?

costales' solution is to simply import sqlite3 and then read Chrome's local storage files. Pretty sweet!

Community
  • 1
  • 1
Dave Burton
  • 2,766
  • 28
  • 18