Neo Posted May 16, 2008 Posted May 16, 2008 Like the Topic title, I would like to know the simplest way to find the link belonging to a text that needs to be found on the current page. Can anyone please help me ? The easiest way to see this is to think about _IELinkClickByText but more like _IELinkCopyByText. Thank you
DaleHohm Posted May 16, 2008 Posted May 16, 2008 So you know the href of a link and you want to find the text of the link? You must loop through the link collection examining the .href property and and when you find the one you want, get the .innerText (or use _IEPropertyGet($oLink, "innerText") ). This is exactly the way that _IELinkClickByText works, so you can open IE.au3 and check it out. Dale Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble
ProgAndy Posted May 16, 2008 Posted May 16, 2008 (edited) I think, he needs the Link, which belongs to a thxt, but don't click it. Do you mean this? ; ******************************************************* ; Example 1 - Open browser with basic example, click on the link ; with text "user forum" ; ******************************************************* ; #include <IE.au3> $oIE = _IE_Example ("basic") MsgBox(0, '', _IELinkGetURLByText ($oIE, "user forum")) ; Function Name: _IELinkGetURLByText() ; Author(s): Prog@ndy, modified from _IELinkClickByText by Dale Hohm Func _IELinkGetURLByText(ByRef $o_object, $s_linkText, $i_index = 0) If Not IsObj($o_object) Then __IEErrorNotify("Error", "_IELinkGetURLByText", "$_IEStatus_InvalidDataType") SetError($_IEStatus_InvalidDataType, 1) Return 0 EndIf ; Local $found = 0, $link, $linktext, $links = $o_object.document.links $i_index = Number($i_index) For $link In $links $linktext = $link.outerText & "" ; Append empty string to prevent problem with no outerText (image) links If $linktext = $s_linkText Then If ($found = $i_index) Then SetError($_IEStatus_Success) Return $link.href &""; don't know, if empty Stringis needed, but better do it :) EndIf $found = $found + 1 EndIf Next __IEErrorNotify("Warning", "_IELinkGetURLByText", "$_IEStatus_NoMatch") SetError($_IEStatus_NoMatch) ; Could be caused by parameter 2, 3 or both Return 0 EndFunc ;==>_IELinkClickByText Edited May 16, 2008 by ProgAndy *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes
Neo Posted May 16, 2008 Author Posted May 16, 2008 (edited) I am able to get the link with a For Loop. But I was wondering if there is a way to actually copy the link of a text instead of clicking it without a Loop. The exact thing I would like is just to obtain the URL from a text that I have on a website, instead of clicking on it to access the link. This must be done without a Loop through all the links (Not using _IELinkGetCollection or at least without looping) though since with the loop I have already done it as per below code. Func FindLinkText($text) ;~ $lprop = _IE $oLink.innerHTML _IELoadWait($oFrameBody) Local $oLink, $oLinks, $linkSplit, $lprop $text = StringStripWS($text, 3) $oLinks = _IELinkGetCollection($oFrameBody) For $oLink In $oLinks If($oLink.innerHTML = $text) Then $linkSplit = StringSplit($oLink.href, ",") $lprop = "java script:UL(62," & $linkSplit[2] Return $lprop EndIf Next EndFunc This is to speed up the process which is taking considerable time due to the number of links in the pages I am working with. As always, thank you very much for your assistance Edited May 16, 2008 by Neo
DaleHohm Posted May 17, 2008 Posted May 17, 2008 You can directly access an element in the DOM by ID, NAME or Index. Any other access requires that you loop through an object collection. Sorry. Dale Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble
Neo Posted May 17, 2008 Author Posted May 17, 2008 Ohhh... Thank you Master once again. I understand. This is still very good I just thought I could copy the link from a text . I will stick to the loop I got. Thanks to you too ProgAndy, much appreciated. I am going to look at that code when I get home and see what can be done Take care all of you and have a wonderful week-end !!!!!!!!
DaleHohm Posted May 17, 2008 Posted May 17, 2008 I have to admit though that I don't know what you mean by "I just thought I could copy the link from a text" - what are you calling a link and what are you calling "a text"? Dale Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble
Neo Posted May 17, 2008 Author Posted May 17, 2008 Sorry, I am confusing you What I mean by text is actually just the text displayed for a link for example: <a href="LINK.HTML">TEXT</a> So I don't want to click on TEXT to access the LINK.HTML but more like extract LINK.HTML from TEXT. I hope this is better. Sorry, and thank you master
DaleHohm Posted May 17, 2008 Posted May 17, 2008 For $oLink In $oLinks If String(_IEPropertyGet($oLink, "innerText")) = "mystring" Then _ ConsoleWrite("The url: " & $oLink.href & @CR) Next Dale Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble
Neo Posted May 17, 2008 Author Posted May 17, 2008 Thank you master This will work perfectly fine. You truly are great.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now