MechanicalSoup is a Python library for automated web browsing and form handling. It is built on top of the requests and BeautifulSoup libraries.
MechanicalSoup is a Python library for automated web browsing and form handling. It is built on top of the requests and BeautifulSoup libraries.
Install with: pip install mechanicalsoup
Example usage:
import mechanicalsoup
# Connect to duckduckgo
browser = mechanicalsoup.StatefulBrowser()
browser.open("https://duckduckgo.com/")
# Fill-in the search form
browser.select_form('#search_form_homepage')
browser["q"] = "MechanicalSoup"
browser.submit_selected()
# Display the results
for l in browser.get_current_page().select('a.result__a'):
print(l.text, '->', l.attrs['href'])