Skip to main content

autobrowser aims to provide tools, with the help of 3rd party modules, to allow users to browse the web programmatically using a web browser. It particularly helps to identify and access content from websites that do not have APIs.

Dependencies

  • Web browser (preferably Firefox)

  • Python 2.7

  • Tornado

  • Selenium

Features

  • Probe:

    to help identify HTML elements and their exact css location in the DOM tree by user mousedown event on the HTML element in the web browser. The HTML elements identified will have a certain attribute set and this attribute set will be saved in the provided file, separated by the caret character ( ^ )

  • execution loop:

    accepts a user function and can run it repeatedly in, either single-threaded sequential manner or multi-process periodical manner

Installation

$ pip install autobrowser

Usage

  • For probing HTML elements in web browser

    • Please ensure to only use the default active tab in the invoked browser for probing.

    • Please let the browser completely load the webpage before starting to probe.

from selenium import webdriver
from autobrowser import probe

wd = webdriver.Firefox()

probe.Probe(wd, <path/to/ssl_privatekey_file>, <path/to/ssl_certificate_file>, <activity_output_file>).start()

Example output

event^datetime^elem_location^elem_id^elem_tagName^elem_className^elem_innerHTML^css_location
mousedown^2015-01-01T12:41:00.691Z^www.google.com.hk/^lst-ib^INPUT^gsfi lst-d-f^^BODY>DIV:nth-child(1)>DIV:nth-child(5)>FORM:nth-child(3)>DIV:nth-child(2)>DIV:nth-child(2)>DIV:nth-child(1)>DIV:nth-child(1)>DIV:nth-child(1)>DIV:nth-child(1)>DIV:nth-child(2)>DIV:nth-child(1)>INPUT:nth-child(1)
mousedown^2015-01-01T12:41:05.202Z^www.google.com.hk/^^INPUT^^^BODY>DIV:nth-child(1)>DIV:nth-child(5)>FORM:nth-child(3)>DIV:nth-child(2)>DIV:nth-child(3)>CENTER:nth-child(1)>INPUT:nth-child(1)
mousedown^2015-01-01T12:41:09.108Z^www.google.com.hk/^^A^^Giant panda - Wikipedia, the free encyclopedia^BODY>DIV:nth-child(1)>DIV:nth-child(7)>DIV:nth-child(3)>DIV:nth-child(7)>DIV:nth-child(2)>DIV:nth-child(3)>DIV:nth-child(1)>DIV:nth-child(2)>DIV:nth-child(2)>DIV:nth-child(2)>DIV:nth-child(2)>OL:nth-child(1)>DIV:nth-child(6)>LI:nth-child(1)>DIV:nth-child(1)>H3:nth-child(1)>A:nth-child(1)
mousedown^2015-01-01T12:41:13.397Z^en.wikipedia.org/wiki/Giant_panda^^SPAN^^Giant panda^BODY>DIV:nth-child(3)>H1:nth-child(4)>SPAN:nth-child(1)
  • For running a function in the execution loop

from autobrowser import utility
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

wd = webdriver.Firefox()

def foo():
    wd.get("http://google.com")

    # you can use the css_location retrieved from the autobrowser Probe in the css selector
    elem = wd.find_element_by_css_selector("BODY>DIV:nth-child(1)>DIV:nth-child(5)>FORM:nth-child(3)>DIV:nth-child(2)>DIV:nth-child(2)>DIV:nth-child(1)>DIV:nth-child(1)>DIV:nth-child(1)>DIV:nth-child(1)>DIV:nth-child(2)>DIV:nth-child(1)>INPUT:nth-child(1)")

    elem.send_keys("cricket")
    elem.send_keys(Keys.RETURN)

# For running repeatedly in sequential manner with '60' seconds delay
utility.FunctionRunner(foo).repeat_sequential(60)

# For running repeatedly in periodic manner every '15' seconds
# with 5 processes
#
# utility.FunctionRunner(foo).repeat_periodic(15, 5)

License

The MIT License

Copyright (c) 2014 Sagar Nilesh Shah

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Release files for autobrowser 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for autobrowser 0.2.0
File Size Uploaded
autobrowser-0.2.0.tar.gz 5.6 kB Details

Release files / autobrowser-0.2.0.tar.gz

Download URL autobrowser-0.2.0.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
4dd9ee5c885684c6a3a960ac47e04f34288b6ab56a5ebacb544bcc07e6ce40ce
BLAKE2b-256 checksum
How to use checksums
9cba53592722f35b529a08dc355ee52b1baa6af040f905189db1f6694a77cf56
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.2.0 This release

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page