Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python WWW macro

i need something like iMacros for Python. It would be great to have something like that:

browse_to('www.google.com')
type_in_input('search', 'query')
click_button('search')
list = get_all('<p>')

Do you know something like that?

Thanks in advance, Etam.

like image 324
Etam Avatar asked Aug 18 '09 16:08

Etam


People also ask

Can I make a macro in Python?

You can write an Excel macro in python to do whatever you would previously have used VBA for. Macros work in a very similar way to worksheet functions. To register a function as a macro you use the xl_macro decorator. Macros are useful as they can be called when GUI elements (buttons, checkboxes etc.)

What is a macro in Python?

The idea of a macro is simply a piece of Python code that can be executed from control system interface (GUI/CLI). Therefore, anything that you don't need to be executed by the interface should NOT be a macro.

Can I use Python in Excel macros?

Run the Python script for Excel Note that you will have to save the Excel workbook as a '. xlsm' file to enable macro functionality. Once this is done, navigate to the 'Developer' tab and select 'Insert' and click on the button icon.

Can Python run VBA macros?

Can Python do everything VBA can? Everything you can write in VBA can be done in Python. This page contains information that will help you translate your VBA code into Python. Please note that the Excel Object Model is part of Excel and documented by Microsoft.


2 Answers

Almost a direct fulfillment of the wishes in the question - twill.

twill is a simple language that allows users to browse the Web from a command-line interface. With twill, you can navigate through Web sites that use forms, cookies, and most standard Web features.

twill supports automated Web testing and has a simple Python interface.

(pyparsing, mechanize, and BeautifulSoup are included with twill for convenience.)

A Python API example:

from twill.commands import go, showforms, formclear, fv, submit

go('http://issola.caltech.edu/~t/qwsgi/qwsgi-demo.cgi/')
go('./widgets')
showforms()

formclear('1')
fv("1", "name", "test")
fv("1", "password", "testpass")
fv("1", "confirm", "yes")
showforms()

submit('0')
like image 55
gimel Avatar answered Sep 20 '22 05:09

gimel


Use mechanize. Other than executing JavaScript in a page, it's pretty good.

like image 31
Vinay Sajip Avatar answered Sep 19 '22 05:09

Vinay Sajip