OpenWPM/demo.py

54 строки
1.9 KiB
Python
Исходник Обычный вид История

2018-08-15 17:30:21 +03:00
from automation import CommandSequence, TaskManager
2014-07-01 20:37:17 +04:00
# The list of sites that we wish to crawl
2020-02-28 19:39:39 +03:00
NUM_BROWSERS = 1
sites = ['http://www.example.com',
'http://www.princeton.edu',
'http://citp.princeton.edu/']
2014-07-01 20:37:17 +04:00
2019-07-14 00:48:58 +03:00
# Loads the default manager params
# and NUM_BROWSERS copies of the default browser params
manager_params, browser_params = TaskManager.load_default_params(NUM_BROWSERS)
2014-07-01 20:37:17 +04:00
# Update browser configuration (use this for per-browser settings)
for i in range(NUM_BROWSERS):
2017-07-28 23:37:35 +03:00
# Record HTTP Requests and Responses
browser_params[i]['http_instrument'] = True
# Record cookie changes
browser_params[i]['cookie_instrument'] = True
# Record Navigations
browser_params[i]['navigation_instrument'] = True
# Record JS Web API calls
browser_params[i]['js_instrument'] = True
# Record the callstack of all WebRequests made
browser_params[i]['callstack_instrument'] = True
# Launch only browser 0 headless
browser_params[0]['display_mode'] = 'headless'
2014-07-01 20:37:17 +04:00
# Update TaskManager configuration (use this for crawl-wide settings)
manager_params['data_directory'] = '~/Desktop/'
manager_params['log_directory'] = '~/Desktop/'
2014-07-01 20:37:17 +04:00
# Instantiates the measurement platform
# Commands time out by default after 60 seconds
manager = TaskManager.TaskManager(manager_params, browser_params)
2014-07-01 20:37:17 +04:00
# Visits the sites
2014-07-01 20:37:17 +04:00
for site in sites:
# Parallelize sites over all number of browsers set above.
2019-09-26 16:22:48 +03:00
# (To have all browsers go to the same sites, add `index='**'`)
command_sequence = CommandSequence.CommandSequence(
site, reset=True,
callback=lambda val=site: print("CommandSequence {} done".format(val)))
# Start by visiting the page
command_sequence.get(sleep=3, timeout=60)
# Run commands across the three browsers (simple parallelization)
manager.execute_command_sequence(command_sequence)
2014-07-01 20:37:17 +04:00
# Shuts down the browsers and waits for the data to finish logging
manager.close()