AnAdventurer

Newbie with a question... or two (IE focused)

5 posts in this topic

#1 ·  Posted (edited)

Hello hello!

As the title suggests, I am fairly new to AutoIt. In fact, I am new to scripting/coding in general! I've done a few Codecademy courses on CSS and HTML and perhaps Java though this was all a few years back. I've recently come across AutoIt and decided to give it a try since I do quite a few repetitive tasks on a daily basis. In the last couple of weeks I've managed to master (or at least get comfortable with) mouse clicks(left/right), window focus, sending key strokes, controls, and pixel search.

Now let's get to the topic.

At this point in time I've tried out a few simple IE scripts but I am having difficulty understanding some things and tying everything together into one tool.

Specifically, I am struggling with this little bit of code I got from DaleHohm in his IE examples thread. Post #3 (The last example.)

#include <IE.au3>

$sImgDir = "c:\foo\"; Please make certain this folder already exists (silent failure if not)
$sWebPage = "http://www.autoitscript.com/forum/index.php?"; webpage with images

$oIE = _IECreate()
_IENavigate($oIE, $sWebPage)
$oIMGs = _IETagNameGetCollection($oIE.document, "img")

; Loop through all IMG tags and save file to local directory using INetGet
For $oIMG in $oIMGs
    $sImgUrl = $oIMG.src
    $sImgFileName = $oIMG.nameProp
    INetGet($sImgUrl,  $sImgDir & $sImgFileName)
Next

I have a couple questions about the code above.

1) ".src" ".nameProp" What are these called? I figured out that I can change the .src to something like .href and it gets anything on the webpage with a .href tag but where can I learn more about these? I still haven't been able to figure out what ".nameProp" is for or what it does. Is there any documentation/list of all the different ".PurpleTextAfterAVariable" (Edit: Not sure why it's red in the above example, just checked SciTE and it's purple there) that I can use?

2) I understand that the code above gets every "For $oIMG in $oIMGs" on the page but how can I make it only get the first 5? I've tried doing a "count" and a "for" but I am unsure what to replace the "For...in" statement with to keep the script functional. Is there a way to limit the _IETagNameGetCollection function to only get a specific amount of tags?

 

Finally, the reason I can't just use the code as is.

The site I am trying to get images from works in this way:

A href= "Link-To-Picture.jpg"

Img src= "Link-To-Picture-thumbnail.jpg"

The script above downloads every single thumbnail from the image gallery which is great, it does what it's supposed to but I need the full resolution image.

After changing the script to get anything with an "A href" tag it does what I need it to do, it gets every single image in full resolution... along with every single one of the 80-100 extra files/links to other sites that are listed under an "A href" tag.

 

Now I've come up with two solutions but unfortunately, as I mentioned above. I don't know how to put my solution into the code above to make it work.

Solution 1) Only get the first 5 instances of "A href" on the page.

As mentioned above. I don't know how to do this.

Solution 2) Read the entire page, find "-Thumbnail.jpg" replace with ".jpg" and use the script as is.

I understand how to do a replace. All I am missing is how to do a replace within a field in the code of an IE page. I assume that I have to use the HTMLRead functions but how do I use/alter the data read?

I really hope all of this make sense and that someone here will be able to help me figure out a solution to my issue or at least answer one of my questions! I do have plenty more questions and I am sure that I'll have even more by the time I figure this out.

Thank you very much for your time!

Edited by AnAdventurer
Double checked a color difference between SciTE and the forum code.

Share this post


Link to post
Share on other sites



Bump

Share this post


Link to post
Share on other sites

 

On 31/10/2016 at 6:59 AM, AnAdventurer said:

I figured out that I can change the .src to something like .href and it gets anything on the webpage with a .href tag

No. your code currently gets all the "img" tags and extracts the information from the ".src" attribute. Changing ".src" to ".href" would just give you the href attribute of the img tags. Based on your code you want the "a" tag, wrapped around your "img" tags? if so try my code below.

On 31/10/2016 at 6:59 AM, AnAdventurer said:

I still haven't been able to figure out what ".nameProp" is for or what it does. Is there any documentation/list of all the different ".PurpleTextAfterAVariable"

The "nameProp" property is acesseble only via the IE object you created in your code. IE documentation could point you in the right direction. Here is documentation for the "nameProp" property: nameProp property

 

The code below should be modified to work with your page.

#include <IE.au3>

$sImgDir = "c:\foo\"; Please make certain this folder already exists (silent failure if not)
$sWebPage = "http://www.autoitscript.com/forum/index.php?"; webpage with images

$oIE = _IECreate()
_IENavigate($oIE, $sWebPage)
$oIMGs = _IETagNameGetCollection($oIE.document, "img")

; Loop through all IMG tags and save file to local directory using INetGet
For $oIMG in $oIMGs
    $oA = $oIMG.parentNode
    If Not ($oA.localName == "a") Then ContinueLoop
    $sImgUrl = $oA.src
    $sImgFileName = $oA.nameProp
    INetGet($sImgUrl,  $sImgDir & $sImgFileName)
Next

 

Share this post


Link to post
Share on other sites
14 hours ago, genius257 said:

The code below should be modified to work with your page.

#include <IE.au3>

$sImgDir = "c:\foo\"; Please make certain this folder already exists (silent failure if not)
$sWebPage = "http://www.autoitscript.com/forum/index.php?"; webpage with images

$oIE = _IECreate()
_IENavigate($oIE, $sWebPage)
$oIMGs = _IETagNameGetCollection($oIE.document, "img")

; Loop through all IMG tags and save file to local directory using INetGet
For $oIMG in $oIMGs
    $oA = $oIMG.parentNode
    If Not ($oA.localName == "a") Then ContinueLoop
    $sImgUrl = $oA.src
    $sImgFileName = $oA.nameProp
    INetGet($sImgUrl,  $sImgDir & $sImgFileName)
Next

 

Thank you so much! I had to change some things around but it works now! I didn't even know you could use a parentnode! Is the msdn site you linked the best source for this type of thing?

Share this post


Link to post
Share on other sites
7 hours ago, AnAdventurer said:

Thank you so much! I had to change some things around but it works now!

Np :) Glad to hear it.

7 hours ago, AnAdventurer said:

Is the msdn site you linked the best source for this type of thing?

Yeah i would say so :)

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Similar Content

    • mjolnirmarkiv
      By mjolnirmarkiv
      Hi!
      Does anyone have any idea why Test() returns 0, while Test2() returns 1?
      #include <IE.au3> MsgBox(0, "", Test() & " " & Test2()) Func Test() Local $oHTML = ObjCreate("HTMLFILE") $oHTML.body.innerHTML = FileRead("Test.html") Return IsObj($oHTML.getElementsByClassName("example")) EndFunc Func Test2() Local $oIE = _IEAttach("", "instance", 1) Return IsObj($oIE.document.getElementsByClassName("example")) EndFunc Sample Test.html I open in IE before testing:
      <!DOCTYPE html> <html> <body> <p class="example"></p> <div class="example"></div> </body> </html> I'm receiving html text in a response to http request, I need to parse it fast and easy, getElementsByClassName would have been ideal. I'm using 3.3.12.0 version.
    • ADIN
      By ADIN
      When at some page i access by  IE.au3 appears javascript alert all my code stops and i cant do nothing. Is there any way to stop executing javascript at this page or any way to force autoit to click "OK" when this alert appears?
       
      _IENavigate($oIE, "www.example.com") _IELoadWait($oIE) ; site is loaded and alert appears Send("{ENTER}") ;i want to close alert, this command is not executed, whole script is freeze ; cant do nothing more here....  
    • ADIN
      By ADIN
      I want use _IEFormGetCollection to get form content which was generated by javascript
      Local $oIE = _IECreate("https://www.example.com/login.html") ;Open the login page Local $oSpans = _IETagNameGetCollection($oIE, "span") For $oSpan In $oSpans if $oSpan.innertext == "Login" Then _IEAction($oSpan, "click") EndIf Next ;click span which ganerate by javascript login form Local $oForm = _IEFormGetCollection($oIE, 0) ;get my form, but that was not on website after loading, appears after click button and this function cant see it Local $oEmail = _IEFormElementGetObjByName($oForm, "email") ; trying to parse form but cant _IEFormElementSetValue($oEmail, "example@gmail.com") ; _IEFormGetCollection dont see generated dynamically elements Is here any way to _IETagNameGetCollection read website content again after i inititate a javascript which generate additional content?
    • dumbledown
      By dumbledown
      Hi,
      I'm new to AutoIt but it looks great.
      I want to get the text from Internet Explorer when hovering the mouse over an image, the statusbargettext function appears to be the way to go.
      When running via a hotkey I return a blank, but the msgbox works. Do you know what I'm doing wrong?
      Thanks
      HotKeySet("!x", "RecordURL") ;wait for ALT-a keystroke While 1 ;loop forever to wait for the keypress Sleep(100) ;no need to kill the CPU WEnd Func RecordURL() #include <MsgBoxConstants.au3> AutoItSetOption("WinTitleMatchMode", 2) Local $sText = StatusbarGetText("Internet Explorer") MsgBox($MB_SYSTEMMODAL, "", "Internet Explorer's status bar says: " & $sText) EndFunc