IE page text collection

xiaoxiao2021-03-06  47

Not long ago, some people seeking a software that can automatically complete the text collection of web text. The specific function is that when the user selects a piece of text in the web page, click the right mouse button, you will see the "Save As Text File" in the Right-click menu, this article tells the technique of this small software I implemented. And thinking.

The technique involved in the software is:

1, IE programming, mainly how to embed the right-click menu to IE right-click menu.

2, COM (Component Object Model) Programming.

3, VB scripting programming.

Implement the basic idea and process of the software:

1. Register a COM component to the system that provides interface SaveText (BSTR STR), and the SaveText interface can save the STR as a text file under the specified path.

2. Modify the registry, add the "Save As Text File" option to the IE right-click menu.

3. Establish a VB script, the associated menu option is called with the COM component.

In this way, the user can select "Save As Text File" after selecting the text, and the program can pass the selected text to the COM component.

Below is a detail to achieve the above three steps: (Development Environment: Visual C 6.0)

1. Establish an ATL project in the VC and add interface SaveText (BSTR STR) to the COM component. This interface calls the SaveText function in SaveText.dll (this function pops up dialog, and saves the content in the text box in the dialog box as The user specifies the text file of the path) to complete the saved text.

2, modify the registry, add "Save As Text File" sub-key under the HKEY_CURRENT_USER / SOFTWARE / Microsoft / Internet Explorer / Menuext / subkey, set up two values, where the default value is the path of the execution script, the contexts value Indicates when the menu option is displayed in the right mouse button in IE (see details

http://support.microsoft.com/kb/q177241/).

3. The purpose of establishing the VB script is to perform this script when the user clicks the "Save As Text File" option, then the script creates a COM object, complete the saved text file function, select the script program for the user to select the text in the web page can be as follows set:

ON Error ResMe next

Set nc = creteObject ("seizetExt.seize")

IF Err <> 0 THEN

Msgbox ("Error ..")

Else

nc.catchhtmltext (external.Menuarguments.Document.selection.createrange (). Text)

END IF

After completing the above steps, the web text acquisition function is implemented.

转载请注明原文地址:https://www.9cbs.com/read-71231.html

New Post(0)