Package: igemwikiscraper
igem-wikiscraperA quick-and-dirty Python CLI tool for scraping iGEM wikis. Can be used to pull out any relevant HTML-based information. Note that this tool will not function on, for example, lab manuals involving PDFs, pages that dynamically load in content on user interaction or page scroll, or pages that redirect to other websites (not that this is allowed by iGEM).UseThis tool currently only functions with Python3. Python2 compatibility is on the backburner. Any instructions assume you have Python3 installed and on PATH.Install viapipor download fromreleasesCreate a new folder to hold all your information and scrapes. AdddataandoutputsubdirectoriesCopyconfig.jsonfromhereinto this new folderRetrieve data fromhttp://igem.org/Team_List.Modifyconfig.jsonas you see fit. Descriptions of config options are availablebelow.Use eitherwikiscraperorwikiscraper-gui. See below.GUIA GUI tool is available. This tool can be accessed viawikiscraper-guionce installed withpip install igemwikiscraper. Steps 1-5 above should be followed before using this GUI.TerminalThese commands should work for Ubuntu. For Windows, substitutepipforpip3. For Mac or other UNIXes, you're on your own.pip3installigemwikiscraper
mkdirigem-scrapescdigem-scrapes
wgethttps://github.com/Virginia-iGEM/igem-wikiscraper/blob/master/igemwikiscraper/config.json
nanoconfig.json# modify as neededmkdir{data,output}cddata
wgethttps://raw.githubusercontent.com/Virginia-iGEM/igem-wikiscraper/master/data/2018__team_list__2018-07-02.csvcd..
wikiscraperdata/2018__team_list__2018-07-02.csvOutput file can be found underoutput/or as configured.Brief Description of Tool FunctionThe tool retrieves raw HTML from URLs generated from a list of team names and years. This raw HTML is then passed through BeautifulSoup, a combination HTML Parser and HTML Selector built specifically for webscraping.Specific HTML tags are removed in preprocessing (such as script and style tags, which we don't need), then a set of tags is selected with an emulated JQuery selector (with thehtmlselectoroption). This set of tags is then "strained" by their content, removing entries that are too short, do not contain sentences, and which contain any JavaScript or CSS motifs.All of the children of selected tags are then unwrapped, discarding their attributes and keeping only their content in (what I believe is) a pre-ordered tree traversal.This process occurs for each page specified bysubpages, leaving us with a list of lists of strings for each team. This 2d list is flattened to 1d by joining the sublists with newlines, before being appended to team information and written out as one row in a .csv file specified byoutputfile. This is repeated for each team in the teamlist, building up a list of team information paired with useful scraped data.ConfigurationNote: Some of these options can be set when using the CLI. Enterwikiscraper -hfor a list of options which can be set through the CLI. This is convenient for options like-vvwhich you may not want to see on every scrape attempt.data: Options for what kind of data we take in and look forsubpages: Which pages on the wiki to look at.""denotes the index. Note that each page is lead with a forward slash; every page must be lead with a forward slash. Examples:/Team,/Safetyfiledelimiter: What kind of csv delimiter is the team name list using? The iGEM Team List page seems to generate CSV's with comma delimiters.start: Which team in the list to start with. Set to negative to remove limit.end: Which team in the list to end with. Set to negative to remove limit.scraper: Options for how the scraper filters and interprets datahtmlselector: JQuery-style selector for html elements.#contentseems to include all hand-written team info without including any extra junk. Upon inspecting many iGEM wikis, we found all contentshouldbe wrapped in#mw-content-text, but because there areso many(about 10% of) iGEM wikis with broken HTML, mostly in the form of unpaired HTML tags, we have to be a bit generous with our selectors.gracetime: Number of seconds to wait between HTML GET requests. Strongly reccommend this to be kept at 1 or above; any lower is considered impolite by web scraping standards, may break the iGEM Wiki, and may be considered a crime (a Denial of Service Attack, albeit a poor one).stripwhitespace: Removes leading and trailing whitespace. Cleans up output a little.collapsenewlines: Removes strings of newlines in retrieved stringsexcisescripts: Removes any script tags when preprocessing HTMLexcisestyles: Removes any style tags when preprocessing HTMLuse: Enables/disables filters listed below.space_count: Filters strings by the number of spaces they contain. If a string has less than this number of spaces, it will be excluded.period_count: Filters string by number of periods contained. If a string has less than this number of periods, it will be excluded.negative_regex: Regex with double-escaped backslashes. If a string matches this regex, it will be excluded.output: Options for the output fileoutputfile: Path to the file we output our results to.filedelimiter: Delimits columns in the output .csv file. Default is a vertical pipe,|, useful for plain HTML content.filequotechar: Used to encapsulate escaped strings in .csv files. Doublequotes"are fairly standard.verbose: Set to0to print progress reports only. Set to1to print useful information above each wiki page scraped. Set to2to print all content scraped.TodoExpand collapsenewlines option to also collapse strings of newlines and tabs into just one newlineMake it so that options underscraper.useactually enable/disable the filterReplaceexcisescriptsandexcisestylesflags with an HTML selector that excises arbitrary HTML elementsEither enable output to multiple files or ensure multiple inputs lead to a sane single output