Ringer: Web Automation by Demonstration
Total Page:16
File Type:pdf, Size:1020Kb
Ringer: Web Automation by Demonstration Shaon Barman Sarah Chasins Rastislav Bodik University of California, Berkeley University of California, Berkeley University of Washington (USA) (USA) (USA) [email protected] [email protected] [email protected] rtifact A Comple * t * te * n * A te Sumit Gulwani is W E s A e n C l l L o D C S o * * c P u e m s E u O e e n v R Microsoft Research (USA) t e O o d t a y * s E a * l u d a e [email protected] t Abstract scrape data for their studies and journalists for their stories (the investigative news organization ProPublica hires pro- With increasing amounts of data available on the web and a grammers to develop web scrapers [2]). Overall, the interest diverse range of users interested in programmatically access- in web automation is growing: the number of StackOverflow ing that data, web automation must become easier. Automa- questions on “scraping” grew by 16% in 2014 and 23% in tion helps users complete many tedious interactions, such as 2015 [34], and commercial scrapers such as Kimono [25] and scraping data, completing forms, or transferring data between import.io [22] appeared during the last three years. websites. However, writing web automation scripts typically Writing good web automation scripts is challenging. Since requires an expert programmer because the writer must be some websites do not offer APIs for accessing their data, able to reverse engineer the target webpage. We have built a retrieving the data programmatically requires reverse engi- record and replay tool, Ringer, that makes web automation neering their webpages’ DOM tree structures and event han- accessible to non-coders. Ringer takes a user demonstration dlers. To remain useful, programs must account for future as input and creates a script that interacts with the page as a changes to webpages, such as website redesigns or updated user would. This approach makes Ringer scripts more robust content. Additionally, on websites that actively attempt to pre- to webpage changes because user-facing interfaces remain vent automated scraping, the programmer must work around relatively stable compared to the underlying webpage im- obfuscation. For instance, some pages wait to load part of plementations. We evaluated our approach on benchmarks a page’s content until the user hovers over or clicks on a recorded on real webpages and found that it replayed 4x more relevant component. Further, modern user interfaces, such benchmarks than a state-of-the-art replay tool. as autocomplete menus and “infinite scrolling,” add to the Categories and Subject Descriptors H.5.3 [Group and Or- complexity of automating web access. ganization Interfaces]: Web-based interaction General Terms Design, Languages 1.1 Approach Keywords Record-Replay, Automation, Javascript, Browser We describe Ringer, a record and replay system that produces 1. Introduction web automation scripts from end-user demonstrations. Ringer Programmatic access to user-facing websites serves a range is based on the observation that while the internals of a web- of purposes: news readers reformat news articles for cleaner page may change, the user-facing interface tends to remain access (e.g., Readability [3]); end users automate tedious in- stable in order to maintain a consistent user experience. Reli- teractions with webpages (e.g., IFTTT [1]); and data scientists able automation can thus be achieved by invoking actions at the level of the user-visible interface, rather than by reverse Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed engineering server requests or JavaScript function calls or for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM other low-levels components of the implementation. must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, Given a user demonstration, Ringer produces a script to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]. that completes the user’s demonstrated task. The script is Copyright is held by the owner/author(s). Publication rights licensed to ACM. a sequence of statements of the form “wait for a condition OOPSLA’16, November 2–4, 2016, Amsterdam, Netherlands C, then perform an action a on a webpage node n.” Ringer ACM. 978-1-4503-4444-9/16/11...$15.00 http://dx.doi.org/10.1145/2983990.2984020 records the sequence of actions in the demonstration. For 748 each action, it produces a condition and a node selector that 1.4 Results make the script robust to certain types of webpage changes. To evaluate Ringer as a whole, we developed a suite of 34 1.2 Applications interaction benchmarks. We compared Ringer to CoScripter, an existing end-user replay tool, and found that CoSripter Because Ringer infers scripts from only a user demonstration, replayed 6 (18%) benchmarks, while Ringer replayed 25 it gives non-programmers access to web automation. Using (74%). We also tested how well Ringer handled page changes Ringer, we built an example application (discussed further by rerunning Ringer scripts over a three-week period. Of the in Section 8.5) that lets non-coders build a homepage with 24 benchmarks that ran initially, 22 (92%) continued to run custom “live information tiles.” Users record how to scrape at the end of the testing period. the day’s flavors at their local ice cream shop, today’s open To set expectations for how well a replayer can perform, hours at their pool, or their current commute time; the custom we must acknowledge that sites are free to modify their homepage replays those interactions to display up-to-date pages arbitrarily at any time. To counteract the inherent best- information. effort nature of the replay problem, Ringer uses previously Ringer benefits expert programmers, too, because record developed techniques [23] to specify invariants, i.e., text that and replay obviates the need for tedious reverse engineering. must appear on a page. We use these invariants to increase the Programmers can simply record an interaction and then confidence that replay has not diverged and as a correctness modify the resulting Ringer script or embed it into a larger condition when evaluating Ringer. application. For example, WebCombine [14], a tool built This paper makes the following contributions: using Ringer, lets a user scrape large datasets from structured • websites. The user demonstrates how to scrape one row of A record and replay approach to webpage automation that the dataset, and WebCombine modifies the resultant Ringer mimics a user’s interactions. We record scripts that use script to scrape all other rows of the dataset. three constructs: actions, nodes and trigger conditions. • A node addressing algorithm based on similarity that 1.3 Technical Challenges identifies nodes across multiple webpage accesses. Replaying recorded actions may appear simple, but funda- • An algorithm that generates trigger conditions by observ- mental challenges make it difficult to mimic a human user, ing multiple replay executions. both spatially (selecting the node on which to apply an action) and temporally (determining the conditions under which the This paper is organized as follows. Section 2 introduces page is ready for the action). the challenges of automating websites and the approaches To solve the spatial problem we must define a reliable Ringer takes to solve them. Ringer’s core language features correspondence between demonstration-time DOM nodes are presented in Section 3, with the temporal problem dis- and replay-time nodes. Given a new version of a webpage, we cussed further in Section 4 and the spatial problem discussed seek the node that a user would select to re-demonstrate the further in Section 5. Section 6 details Ringer’s implementa- interaction. Existing solutions [6, 27, 36] are fragile because tion, and Section 7 details its limitations. In Section 8, we they require a few key node attributes to remain constant. present an evaluation of Ringer on a set of benchmark web- In contrast, our approach selects the replay-time node that sites. Finally, Section 9 offers a discussion of related work. maximizes a similarity metric. A longitudinal study of 30 2. Challenges in Web Automation webpages found that after 37 days our approach still identified 83% of nodes, 22 percentage points more than the next best Using a running example, we describe the inherent challenges approach. of the web automation approaches currently available to pro- To solve the temporal problem we must determine when grammers (Sections 2.1 and 2.2) and how Ringer addresses the webpage is ready for the next user action. Modern interac- these challenges while making automation accessible to end tive webpages often use visual cues, like showing a loading users (Sections 2.3 and 2.4). bar, to signal that they are waiting for responses from a server. 2.1 Web Automation Scripts Written by Programmers An impatient user (or a naive replay tool) might ignore the cue and use stale data, producing unexpected behaviors. Al- Consider the task of searching Amazon for a given camera though these visual cues are intuitive to humans, existing model, selecting the silver-colored camera from a list of color replay techniques are oblivious to them. To address the tem- options, then scraping its price. Perhaps a user wants to au- poral problem, Ringer replays scripts multiple times to infer tomate this process to detect when the price drops below triggers — conditions that must be met before each script a fixed amount.