How to get the selected text of the webpage in chrome through python ?

Dave Angel d at davea.name
Tue Jan 8 14:11:30 CET 2013


On 01/08/2013 07:38 AM, Dennis Lee Bieber wrote:
> On Mon, 7 Jan 2013 20:20:28 -0800 (PST), iMath <redstone-cold at 163.com>
> declaimed the following in gmane.comp.python.general:
>
>> How to get the selected text of the webpage in chrome through python ?
> 	Chrome is a browser, is it not... If you want to get the text in
> Python, you have to write the equivalent of a browser -- something that
> parses the returned HTML message, extracting the parts you want.

To get a selection, you can either wait till it's copied to the
clipboard, and get it from there, or you can write a addon for the
application.  Since Chrome accepts addons, I suggest you research that
angle.  Probably mozilla.org is the place to start, and function

nsISelectionController::GetSelection() might be some place to examine.

You might find some hints in
http://stackoverflow.com/questions/2671474/range-selection-and-mozilla


if you are going to work with the clipboard, realize that it works quite
differently from one OS to another, and even from one desktop manager to
another.

-- 

DaveA




More information about the Python-list mailing list