Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Auto-copy specific data from webpages



  • Please log in to reply
14 replies to this topic
HeroMax
  • Members
  • 5 posts
  • Last active: Apr 27 2015 05:20 PM
  • Joined: 27 Jun 2014

Hello! I use AHK for a longer time already, but all I can do is creating simple hotkeys (I never had the need for something bigger). The script that I would like to create now exceeds my abilities and it would take a lot of time to learn all the stuff required for making this script.

That's why I would like to request this script here, in the hope that someone is in the mood to create one (if it's not too much trouble). Or if someone could at least point me to the relevant tutorial docs which contain the necessary ahk features to create such a script, or even to an already existing similar script, that would be asweome too! :)

The Goal

So I have this big excel list of player names (sorted in alphabetic order):

1fIabic.png

Now I would like to have the 2 columns rank & guild auto-completed with the help of AHK, since doing it manually is very time consuming. I also plan to update the list once in a while (every 2nd month or so).

The guild and rank information for every player can be found on this site:
http://www.realmeye.com/

For example, to view the player page of the player GoobyPless, I just need to type his player name in the search field, or just directly include his name in the url right after "realmeye.com/player/":
http://www.realmeye....ayer/goobypless

The player page looks like this:

uFCL1rS.png


As you can see, GoobyPless' rank is a yellow star, and his guild is The Stunning. These 2 values should now be copied to the excel chart in the corresponding columns.

That's all! Now the ahk script just needs to do it for every single player listed in the excel chart. :p
 

Guild & Rank in Source Code

The guild and rank data of a player in realmeye.com is also included in the source code of the page:

Rank

tqrNq7y.png

Syntax of the rank:
<div class="star star-yellow">

in general:
<div class="star star-PLAYER_RANK">

note: in total there are 6 ranks:
rNCnG2k.png


Guild
C5HuV1Z.png

Syntax of the guild name:
<a href="/guild/The Stunning">The Stunning</a>

in general:
<a href="/guild/GUILD_NAME">GUILD_NAME</a>

 

How the script could work

1) switch to excel window

2) copy the first player name from the excel chart, in this case it's "Aarbies"

3) switch to firefox

4) go to http://www.realmeye.com/player/Aarbies

5) open the page's source code

6) getting the player's rank
- search for the phrase star star-
- copy the phrase between star star- and ">
- that's the player's rank --> in this example it's yellow

7) getting the player's guild name
- search for the phrase guild/
- copy the phrase between guild/ and ">
- that's the player's guild name --> in this example it's The Stunning

8) close the source code page

9) swich back to excel

10) paste the copied rank and guild name in the corresponding columns/row

11) That's it. Now the ahk script starts over again (loop), but now with the next player --> repeat for every single player in the excel list

Note#1: Maby it's easier/faster to paste the gained player data in a notepad editor instead of directly pasting them in the corresponding excel cells. I could then simply copy the collected data from the notepad file into the excel chart when the ahk script finished its work.

Note #2: Some profiles are "hidden" and not accessible:
DgA7MgH.png

In this case, the ahk scripts just needs to skip the "hidden" player (do nothing) and go on with the next player in the excel chart.

Note #3: Some players have no guild:
2Qugufd.png

In this case, the ahk scripts needs to leave the guild cell of the specific player blank. For example, if PlayerA already had a guild in the past but now is guildless, his cell will now be blank.
 

Thanks for your replies!



lifeweaver
  • Members
  • 868 posts
  • Last active: Jan 25 2016 01:29 AM
  • Joined: 04 Mar 2013

Hi HeroMax,

 

I recommend you use IE and Excel's COM interface, however you would have to use IE and not firefox.

p.s. I, at least cannot see your pictures.


My script runs in A_AhkVersion:=1.1.22.07, get the latest version at http://ahkscript.org/download/

Check out this AutoHotkey tutorial: http://ahkscript.git...o/AHK_Tutorial/

Read the documentation: http://ahkscript.org.../AutoHotkey.htm


HeroMax
  • Members
  • 5 posts
  • Last active: Apr 27 2015 05:20 PM
  • Joined: 27 Jun 2014

Thanks for the links lifeweaver, I will read through the tutorials and see if I can create a working script.

 

The reason why you can't view the images is probably because you have all images blocked from imgur.com.

 

Can you see the image by clicking on the imgur link?

http://imgur.com/rNCnG2k

 

Or by directly the image url?

http://i.imgur.com/rNCnG2k.png



HeroMax
  • Members
  • 5 posts
  • Last active: Apr 27 2015 05:20 PM
  • Joined: 27 Jun 2014

sorry double post by accident



lifeweaver
  • Members
  • 868 posts
  • Last active: Jan 25 2016 01:29 AM
  • Joined: 04 Mar 2013

It's probably the firewall I'm behind.


My script runs in A_AhkVersion:=1.1.22.07, get the latest version at http://ahkscript.org/download/

Check out this AutoHotkey tutorial: http://ahkscript.git...o/AHK_Tutorial/

Read the documentation: http://ahkscript.org.../AutoHotkey.htm


Jackie Sztuk _Blackholyman
  • Spam Officer
  • 3757 posts
  • Last active: Apr 03 2016 08:47 PM
  • Joined: 28 Feb 2012
I'd say something like lifeweaver and i'd also be happy write you an example if you need it

Ps. I Can see your images just fine :)
Helping%20you%20learn%20autohotkey.jpg?d

[AHK] Version. 1.1+ [CLOUD] DropBox ; Copy [WEBSITE] Blog ; About

HeroMax
  • Members
  • 5 posts
  • Last active: Apr 27 2015 05:20 PM
  • Joined: 27 Jun 2014

Ok based on the IE and Excel's COM tutorials , I put together a rough, uncompleted first script.

 

Besides a lot of possible bugs and mistakes, the main parts missing are extracting the actual guild name and player rank from the player's realmeye.com page. I don't know how to access the site's source code, search for the guild/rank syntaxes, and finally extract the player's guild/rank.

 

Further help would be greatly appreciated!

 

@Blackholyman: An example would be awesome, thanks for offering your help! :)

Xl := ComObjActive("Excel.Application") ;open the active excel file

while (Xl.Range("A" . A_Index).Value != "") ; repeat for every player in the excel list
{

;copy playername from the excel list
player  :=  Xl.Range("A" . A_Index).Value
playerlink  :=  realmeye.com/player/%player%

;switch to IE and go to the player's realmeye.com page
wb := ComObjCreate("InternetExplorer.Application")
wb.Visible := True
wb.Navigate(playerlink)

;waiting for the site to finish loading
IELoad(wb)    
{
    If !wb    
        Return False
    Loop    
        Sleep,100
    Until (wb.busy)
    Loop    
        Sleep,100
    Until (!wb.busy)
    Loop    
        Sleep,100
    Until (wb.Document.Readystate = "Complete")
Return True
}

;open the source code of the page

;search for the player's guild name and extract it

;search for the player's rank  and extract it

;store guild name and player rank in variables
guild := extracted_guildname
rank := extracted_rank

;switch back to excel
Xl := ComObjActive("Excel.Application")

;insert guildname/rank to the corresponding column
Xl.Range("B" . A_Index).Value := guild 
Xl.Range("C" . A_Index).Value := rank  
}


lifeweaver
  • Members
  • 868 posts
  • Last active: Jan 25 2016 01:29 AM
  • Joined: 04 Mar 2013

If you use IE's developer tools(Press F12) it can be very easy.

 

Basically:

  1. Press F12
  2. Click the mouse pointer in the opened toolbar(might be a second window, or be on bottom of screen)
  3. Now click the element your interested in.
  4. The tool bar should now show you where that element is in the html.

Note: Chrome and firefox have a similar tool.


My script runs in A_AhkVersion:=1.1.22.07, get the latest version at http://ahkscript.org/download/

Check out this AutoHotkey tutorial: http://ahkscript.git...o/AHK_Tutorial/

Read the documentation: http://ahkscript.org.../AutoHotkey.htm


atnbueno
  • Members
  • 91 posts
  • Last active: Feb 16 2016 07:04 PM
  • Joined: 24 Mar 2007
✓  Best Answer

HeroMax, you may find the following code useful:

PlayerName := "GoobyPless"

UrlDownloadToFile, % "http://www.realmeye.com/player/" PlayerName, TempFile
FileRead, HTML, TempFile
FileDelete, TempFile

RegExMatch(HTML, "s)""star star-(?P<Rank>.+?)"".+""/guild/(?P<Guild>.+?)""", Player)
MsgBox, % "Name: " PlayerName "`nRank: " PlayerRank "`nGuild: " PlayerGuild

HTH,

Antonio

 

P.S. Have you considered working with CSV files? It seems to me your scenario is simple enough that you can just work with text files and skip working with COM objects. Also, no Excel required ;)

 

P.P.S. What the heck. It's not that much code:

Output := ""
Loop, Read, players.csv
{
	Loop, Parse, A_LoopReadLine, CSV
	{
		If (A_Index == 1) {
			UrlDownloadToFile, % "http://www.realmeye.com/player/" A_LoopField, TempFile
			FileRead, HTML, TempFile
			FileDelete, TempFile
			RegExMatch(HTML, """star star-(?P<Rank>.+?)""", Player)
			RegExMatch(HTML, """/guild/(?P<Guild>.+?)""", Player)
			Output .= A_LoopField "," PlayerRank "," PlayerGuild "`r`n"
		}
	}
}
FileDelete, players.csv
FileAppend, % Output, players.csv

Before running the script, players.csv was like this:

Aarbies
AcePajace
HeroMax
Stration
Aboveninja

After running it:

Aarbies,blue,The Belgian Brothers
AcePajace,,
HeroMax,yellow,Nightingale
Stration,blue,
Aboveninja,blue,ThreeSixMafia

B)



Jackie Sztuk _Blackholyman
  • Spam Officer
  • 3757 posts
  • Last active: Apr 03 2016 08:47 PM
  • Joined: 28 Feb 2012
@ atnbueno ofc but its still a nice thing to learn happy.png
 
 
@HeroMax
 
Example:
 
FileSelectFile, file, 2, %A_ScriptDir%, Select an excel file:, *.xls; *.xlsx; *.xlsm
if Errorlevel
   ExitApp
   
oExcel := ComObjCreate("Excel.Application")
oApp := oExcel.application
oApp.DisplayAlerts := false
oExcel.Visible := true
oWorkbook := oExcel.Workbooks.open(file)

wb := ComObjCreate("InternetExplorer.Application")
wb.Visible := true

while (oExcel.Range("A" . A_Index).Value != "")
{
	name  :=  oExcel.Range("A" . A_Index).Value


	wb.Navigate("http://www.realmeye.com/player/" Name)
	while wb.readyState!=4 || wb.document.readyState != "complete" || wb.busy
		sleep 10
	try
	{
	oTable := wb.document.getElementsByTagName("table")[0]
	;~ msgbox % "Rows = " oTable.rows.length "`nCells = " oTable.cells.length "`nRow:4 Cell:2 = " oTable.rows[3].cells[1].Innertext
	Rank := oTable.rows[3].cells[1].Innertext
	Star := RegExReplace(oTable.rows[3].cells[1].getElementsByTagName("div")[1].classname, "^\w+\s\w+-")
	Guild := oTable.rows[5].cells[1].Innertext
	msgbox % "insert `nRank " Rank . Star "`nGuild " Guild "`nin Excel with oExcel.Range(""B"" . A_index).value := Rank"
	}
}


oExcel.quit()
wb.quit()
Msgbox Done!
return
it still needs a little more work but it works as an example happy.png
Helping%20you%20learn%20autohotkey.jpg?d

[AHK] Version. 1.1+ [CLOUD] DropBox ; Copy [WEBSITE] Blog ; About

HeroMax
  • Members
  • 5 posts
  • Last active: Apr 27 2015 05:20 PM
  • Joined: 27 Jun 2014

@atnbueno

 

Wow, your script works great, super fast, and the script code is very short! Compared to the COM object variant, it looks quite simple and clear. Thanks a lot for sharing your script suggestion! :)

 

@ atnbueno ofc but its still a nice thing to learn happy.png

 

 

True. I prefer the short csv variant, but I will check out your example aswell. Thanks for sharing your example Blackholyman!



d3bu99er
  • Members
  • 2 posts
  • Last active: Oct 24 2014 06:15 AM
  • Joined: 23 Oct 2014
Hi guys! 
I'm from Russia, I am sorry for my English, and for the fact that I write in this topic. 
Tell me how to implement a grabber nicks here
Thank you!


Jackie Sztuk _Blackholyman
  • Spam Officer
  • 3757 posts
  • Last active: Apr 03 2016 08:47 PM
  • Joined: 28 Feb 2012


Hi guys!
I'm from Russia, I am sorry for my English, and for the fact that I write in this topic.
Tell me how to implement a grabber nicks here?
Thank you!

Sorry but your need is not clear to me! Please give more info.
Helping%20you%20learn%20autohotkey.jpg?d

[AHK] Version. 1.1+ [CLOUD] DropBox ; Copy [WEBSITE] Blog ; About

d3bu99er
  • Members
  • 2 posts
  • Last active: Oct 24 2014 06:15 AM
  • Joined: 23 Oct 2014

Sorry but your need is not clear to me! Please give more info.

 

I want to collect all the nicks from the page into a file.

Tell me how to implement it?



atnbueno
  • Members
  • 91 posts
  • Last active: Feb 16 2016 07:04 PM
  • Joined: 24 Mar 2007

If it's just the usernames, this should be enough:

Output := ""
UrlDownloadToFile, % "http://www.realmeye.com/top-players-by-fame", TempFile
FileRead, HTML, TempFile
FileDelete, TempFile
Position := 1
While Position > 0
{
	Position := RegExMatch(HTML, "<a href=""/player/.+?"">(?<Name>.+?)</a>", Player, Position+1)
	Output .= PlayerName "`r`n"
}
FileDelete, playerlist.csv
FileAppend, % Output, playerlist.csv

HTH,

Antonio


Regards,
Antonio