GithubHelp home page GithubHelp logo

gwecho / mechanicalsoup Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mechanicalsoup/mechanicalsoup

0.0 2.0 0.0 326 KB

A Python library for automating interaction with websites.

License: MIT License

mechanicalsoup's Introduction

MechanicalSoup

A Python library for automating interaction with websites. MechanicalSoup automatically stores and sends cookies, follows redirects, and can follow links and submit forms.

Installation

Latest Version

From PyPI

 pip install MechanicalSoup

Rationale

WWW-Mechanize and Mechanize are similar Perl and Ruby libraries. Unfortunately, their Python sister project has become inactive, and is now incompatible with recent Python versions (Python 3.x). This library provides a similar API, built on Python giants Requests (for http sessions) and BeautifulSoup (for document navigation).

Example

From example.py, code to log into the GitHub website:

import mechanicalsoup

browser = mechanicalsoup.Browser()

# request github login page
login_page = browser.get("https://github.com/login")

# find login form
login_form = login_page.soup.select("#login")[0].select("form")[0]

# specify username and password
login_form.select("#login_field")[0]['value'] = "username"
login_form.select("#password")[0]['value'] = "password"

# submit form
page2 = browser.submit(login_form, login_page.response.url)

# verify we are now logged in
assert page2.soup.select(".logout-form")

# verify we remain logged in (thanks to cookies) as we browse the rest of the site
page3 = browser.get("https://github.com/colonelpanic/MechanicalSoup")
assert page3.soup.select(".logout-form")

For an example with a more complicated form (with checkboxes, radio buttons and textareas), read tests/test_browser.py.

Development

Build Status

Tests

py.test

mechanicalsoup's People

Contributors

hickford avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.