Filter ChromiumProfileFolder data with KeySearch
masterMethods in ChromiumProfileFolder that retrieve data support a KeySearch interface for filtering. You can pass the following types to search/filter results:
str: Performs an exact match on the value.- Collection of
str(e.g.,listortuple): Matches if the value is exactly one of the items in the collection. re.pattern: Performs a regex search (equivalent tore.search).- Function: A callable that takes a
strand returns aboolindicating a match.
import re
import pathlib
from ccl_chromium_reader import ChromiumProfileFolder
profile_path = pathlib.Path("profile path goes here")
with ChromiumProfileFolder(profile_path) as profile:
# Match one of two possible hosts exactly, then a regular expression for the key
for ls_rec in profile.iter_local_storage(
storage_key=["http://not-a-real-url1.com", "http://not-a-real-url2.com"],
script_key=re.compile(r"message\d{1,3}?-text")
):
print(ls_rec.value)
# Match all urls which end with "&read=1" using a lambda function
for hist_rec in profile.iterate_history_records(url=lambda x: x.endswith("&read=1")):
print(hist_rec.title, hist_rec.url)