-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrawl_web.py
More file actions
55 lines (46 loc) · 1.97 KB
/
crawl_web.py
File metadata and controls
55 lines (46 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import pandas as pd
from automation import CommandSequence, TaskManager
# The list of sites that we wish to crawl
NUM_BROWSERS = 3
site_data = pd.read_csv('/home/alex/Desktop/top-1m.csv')
sites = site_data.iloc[:100,1]
# Loads the default manager params
# and NUM_BROWSERS copies of the default browser params
manager_params, browser_params = TaskManager.load_default_params(NUM_BROWSERS)
# Update browser configuration (use this for per-browser settings)
for i in range(NUM_BROWSERS):
# Record HTTP Requests and Responses
browser_params[i]['http_instrument'] = True
# Record cookie changes
browser_params[i]['cookie_instrument'] = True
# Ad blocking
browser_params[i]['ublock-origin'] = False
# 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[i]['display_mode'] = 'headless'
# Update TaskManager configuration (use this for crawl-wide settings)
manager_params['data_directory'] = '~/Desktop/'
manager_params['log_directory'] = '~/Desktop/'
# Instantiates the measurement platform
# Commands time out by default after 60 seconds
manager = TaskManager.TaskManager(manager_params, browser_params)
# Visits the sites
for site in sites:
http_header = 'http://'
site = http_header + site
# Parallelize sites over all number of browsers set above.
command_sequence = CommandSequence.CommandSequence(
site, reset=True,
callback=lambda success, 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)
# Shuts down the browsers and waits for the data to finish logging
manager.close()