Elitist Jerks
Register
Blogs
Forums


Go Back   Elitist Jerks » Public Discussion

Reply
 
LinkBack Thread Tools
Old 07/05/07, 10:03 AM   #1
zork
Don Flamenco
 
zork's Avatar
 
Dwarf Warrior
 
Eredar (EU)
How to get XML with PHP from armory

*Update*

Since my old tutorial files are lost I made some new ones.

You can check them out here:
php_ajax_armory_tutorial - rothui - Google Code

Three files are needed.
- A basic PHP file that does the structure and includes links that will call your AJAX function
guild_data.php - rothui - Google Code

- Some JavaScript functions to retrieve stuff
armory.js - rothui - Google Code

- Another PHP file that is called by the AJAX function and retrieves the information for you
get_char_data_xml.php - rothui - Google Code

As some posts on page 3 already have mentioned we are now using a class that contains the retrieved information.

If your webserver does not support CURL you can try this function to get the XML string instead. If it does support CURL you should make use of it.
  function get_xml_data_from_url($url,$lang)
  {        
    
$url_array parse_url($url);
    
$fp fsockopen($url_array['host'], 80$errno$errstr5); 
    
$send "GET " $url_array[path] . "?" $url_array[query] ." HTTP/1.0\r\n";
    
$send .= "Host: " $url_array[host] . " \r\n";
    
$send .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\r\n";
    
$send .= "Accept-Language: " $lang "\r\n";
    
$send .= "Connection: Close\r\n\r\n";
    
fwrite($fp$send);
    while (
$fp && !feof($fp))
    {
      
$headerbuffer fgets($fp1024);
      if (
urlencode($headerbuffer) == "%0D%0A")
      {
        break;
      }
    }
    
$xml_data '';
    while (!
feof($fp))
    {
      
$xml_data .= fgets($fp1024);
    }
    
fclose($fp);
    return 
$xml_data;
  } 
Remember: If you do not support the Request with a browser information the response will be HTML and not XML always. So if you want an XML response add some kind of user agent information. But sometimes HTML is wanted, tooltips for example.

Oh btw...Don't spam the armory server with requests or you will find yourself banned temporarily shortly after.

Last edited by zork : 07/15/09 at 10:36 AM.


Offline
Reply With Quote
Old 07/05/07, 10:14 AM   #2
Goggles
King Hippo
 
Goggles's Avatar
 
Selggog
Dwarf Shaman
 
No WoW Account (EU)
Thanks for this. I had originally intended to do some playing with data from the Armory but PHP (and web development in general) is not something I have much experience with so I never got sufficiently motivated to do it. I think this will give me the impetus to have another go as it means I don't need to spend ages working out how to get the data and concentrate on the manipulation of it.

Not actually a member of Refusion on Burning Blade.

Offline
Reply With Quote
Old 07/05/07, 10:38 AM   #3
zork
Don Flamenco
 
zork's Avatar
 
Dwarf Warrior
 
Eredar (EU)
Just to give you some quick example what can be done:

http://dm.next-gen.org/files/item_to...980&lang=fr-fr
http://dm.next-gen.org/files/item_to...980&lang=de-de
http://dm.next-gen.org/files/item_to...980&lang=en-en

Source:
http://dm.next-gen.org/files/item_tooltip_xml.html

So you could have tooltips for every item id you want in multiple languages with just one little script that you could call with AJAX in real time.

If you want to lookup for items per "name", no problem. I want every item with "onslaught" in it. (beware of browser language!)
http://armory.worldofwarcraft.com/se...uery=Onslaught

Ok now with the php script:
http://dm.next-gen.org/files/item_qu...en&q=onslaught
http://dm.next-gen.org/files/item_qu...de&q=onslaught
http://dm.next-gen.org/files/item_qu...fr&q=onslaught

Just have the query string you are searching for behind the "q=".

Source:
http://dm.next-gen.org/files/item_query_xml.html

Thats it.

Last edited by zork : 07/05/07 at 11:28 AM.


Offline
Reply With Quote
Old 07/05/07, 12:56 PM   #4
 sp00n
banned
 
Night Elf Rogue
 
Wrathbringer (EU)
I admit I haven't done any XML parsing yet, but did you take a look at http://www.php.net/manual/en/ref.xml.php?

You should be able to read XML files without having to convert them.


BTW, those links don't work for me:
http://dm.next-gen.org/files/item_qu...en&q=onslaught


Offline
Reply With Quote
Old 07/05/07, 2:24 PM   #5
Pomperipossa
Von Kaiser
 
Undead Warlock
 
<n/a>
Outland (EU)
Originally Posted by sp00n View Post
BTW, those links don't work for me:
http://dm.next-gen.org/files/item_qu...en&q=onslaught
Like in you can't connect or you just get a blank page? If it's the latter you need to look at the source of the page: View->Source code or something like that.

Offline
Reply With Quote
Old 07/05/07, 3:32 PM   #6
 Asmik
snow hook
 
Asmik's Avatar
 
Fiddler Asmik
Orc Warrior
 
No WoW Account
I'm getting the following error, but it's probably because I don't know what I'm doing.


Last edited by Asmik : 07/06/07 at 9:17 AM.

Canada Online
Reply With Quote
Old 07/05/07, 4:26 PM   #7
Renew
Team Healbot
 
Renew's Avatar
 
Cleanse
Human Paladin
 
No WoW Account
http://phparmory.sourceforge.net/ or http://sourceforge.net/projects/phparmory/ is a parse I found around the net that puts everything into php arrays. It's pretty neat and easy to add in your own code (if you know a bit of PHP). I added in some code to get Arena Teams for use on my guilds under dev new layout and it works nice.

Confidence is not Arrogance.

United States Offline
Reply With Quote
Old 07/05/07, 5:35 PM   #8
D1g1talS0ul
Glass Joe
 
Night Elf Priest
 
Cenarius
I use cURL to pull down the xml and simplexml to parse it for my guilds roster page. Requires PHP5, which most webhosts haven't switched to (including our host). I run the script below on my desktop that has PHP5, it parses the info I need and puts it into a mysql database at our host. Then on our hosts server with PHP4, roster.php parses the data from the mysql database.

#!/usr/bin/php
<?php

class roster_gen {

 const 
BROWSER="Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.2) Gecko/20070319 Firefox/2.0.0.3";

 public 
$query;
 public 
$server;
 public 
$guild;
 public 
$guildie;
 public 
$page;

public function 
__construct $query$server$guild$guildie$page ) {
    
$this->query $query;
    
$this->server $server;
    
$this->guild $guild;
    
$this->guildie $guildie;
    
$this->page $page;
 } 
// end of __construct()

public function pull_xml() {

    if( 
$this->query === 'roster' ){
        
$url 'http://armory.worldofwarcraft.com/guild-info.xml?r=' $this->server '&n=' $this->guild '&p=' $this->page;
        
      }elseif( 
$this->query === 'character' ){
        
$url 'http://armory.worldofwarcraft.com/character-sheet.xml?r=' $this->server '&n=' $this->guildie;
        
        }

    
$ch curl_init();
    
curl_setopt ($chCURLOPT_URL$url);
    
curl_setopt ($chCURLOPT_RETURNTRANSFER1);
    
curl_setopt ($chCURLOPT_CONNECTTIMEOUT15);
    
curl_setopt ($chCURLOPT_USERAGENT,  roster_gen::BROWSER);
    
    
$url_string curl_exec($ch);
    return 
simplexml_load_string($url_string);
    
    
curl_close($ch);
 } 
// end of pull_xml()

// end class

// query, realm, guild, guildie, page
// query can be roster or character
$roster = new roster_gen (rostercenariusinsurrectionNULL1);

$xml_roster $roster->pull_xml();
$battlegroup $xml_roster->guildInfo->guild['battleGroup'];
$num_guildies $xml_roster->guildInfo->guild->members['memberCount'];

$roster->query=character;
$name 'someguildie';  //change to character you'd like to lookup
$roster->guildie=$name;
$xml_char $roster->pull_xml();

$tree1 $xml_char->characterInfo->characterTab->talentSpec['treeOne'];
$tree2 $xml_char->characterInfo->characterTab->talentSpec['treeTwo'];
$tree3 $xml_char->characterInfo->characterTab->talentSpec['treeThree'];
            
$lastLOGIN =  $xml_char->characterInfo->character['lastModified'];
            
$title =  $xml_char->characterInfo->character['title'];

echo 
"Guild:$roster->guild Realm:$roster->server Battlegroup:$battlegroup\n";
echo 
"Name:$name($title), Talents:$tree1/$tree2/$tree3 Last Login: $lastLOGIN\n";
?>
If you do a var_dump($xml_char) or var_dump($xml_roster) you'll see all the options you can pull from the armory.

Hope this is helpful.

Offline
Reply With Quote
Old 07/05/07, 9:44 PM   #9
Ragnor
King Hippo
 
Human Paladin
 
Blackrock
I was mucking around testing with Firefox, IE7 and Safari for Windows today and I happened to notice Safari is awesome for using the armory (mostly). Firefox and IE7 will choke/lock up on the large xmlhttprequests and not respond until they have finished loading/processing the page. Safari however will let you carry on no problems, opening new tabs etc while the armory is loading in the background tab.

It's a pain Safari doesn't render text white in input boxes though

The universe is run by the complex interweaving of three elements. Energy, matter, and enlightened self-interest.

www.retpaladin.com

Offline
Reply With Quote
Old 07/06/07, 4:09 AM   #10
 sp00n
banned
 
Night Elf Rogue
 
Wrathbringer (EU)
Originally Posted by Pomperipossa View Post
Like in you can't connect or you just get a blank page? If it's the latter you need to look at the source of the page: View->Source code or something like that.
Huh, yeah.
Weird, normally Firefox displays the XML data and doesn't just put out a blank page.


Offline
Reply With Quote
Old 07/06/07, 4:44 AM   #11
zork
Don Flamenco
 
zork's Avatar
 
Dwarf Warrior
 
Eredar (EU)
Originally Posted by Asmik View Post
I'm getting the following error, but it's probably because i don't know what I'm doing.

The XML data is not for viewing in your browser , its for your php scripts.
So it doesn't matter that you do not see nothing.

Just look into the source to see the XML.

The Armory XML is very very fast, what makes the application so slow is all the AJAX crap. It just eats the browser alive >_<.

@renew
Thanks for the link I will take a closer look at this one. I am now at the point where I have to transfer the XML data into PHP arrays.

Last edited by zork : 07/06/07 at 10:29 AM.


Offline
Reply With Quote
Old 07/06/07, 10:34 AM   #12
Melnor
Piston Honda
 
Melnor's Avatar
 
Blood Elf Paladin
 
Blackhand
Thanks for the insight zork. I'll begin the c# asp.net port shortly. There's probably already one out there but I'm bored.

Offline
Reply With Quote
Old 07/06/07, 2:01 PM   #13
christide
Von Kaiser
 
Tauren Druid
 
Blackrock
Originally Posted by Melnor View Post
Thanks for the insight zork. I'll begin the c# asp.net port shortly. There's probably already one out there but I'm bored.
static HttpWebRequest RequestBuilder(string requestUri, string currentPage, string referer, string address)
	{
		Cookie cookieOne = new Cookie("currentPage", currentPage);
		Cookie cookieTwo = new Cookie("cookies", "true");
		Cookie cookieThree = new Cookie("cookieMenu", "all");

		cookieOne.Domain = address;
		cookieTwo.Domain = address;
		cookieThree.Domain = address;

		CookieContainer thisContainer = new CookieContainer();

		thisContainer.Add(cookieThree);
		thisContainer.Add(cookieTwo);
		thisContainer.Add(cookieOne);

		HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestUri);

		request.Accept = "*/*";
		request.Headers.Add(HttpRequestHeader.AcceptLanguage, "en-us");
		request.Headers.Add("US-CPU", "x86");
		request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.04506; .NET CLR 1.1.4322)";
		request.Referer = referer;
		request.CookieContainer = thisContainer;

		return request;
	}
The ugly hacked up function I wrote a while back to form a request object with the required parameters to get the xml back.

I would call it like:

HttpWebRequest request = RequestBuilder("http://" + address + "/guild-info.xml?r=" + serverName + "&p=1&n=" + guildName + "&lang=", @"guild-info.xml%3Fr%3D" + serverName + "%26n%3D" + guildName + "%26p%3D1", @"http://" + address + "/#guild-info.xml?r=" + serverName + "&n=" + guildName + "&p=1", address);
Used for http://www.thepalsforlife.com/ftp/ArmoryParse/. If you're offended by the word faggot, that link will most likely be extremely offensive.


EDIT: I attached the source to my armory parse. It's pretty ugly and completely devoid of comments since it's something I hacked up in an afternoon and never really bothered with again. Hopefully someone can get some value out of the source however.
Attached Files
File Type: zip armoryparse.zip (4.1 KB, 441 views)

Last edited by christide : 07/06/07 at 2:07 PM.

Offline
Reply With Quote
Old 07/10/07, 6:26 AM   #14
zork
Don Flamenco
 
zork's Avatar
 
Dwarf Warrior
 
Eredar (EU)
I just want to give you an update on this to show what amazing stuff can be done.

I built our own item search based on the Armory XML, take a look



All data is generated in real time, no database is used.

p.s. I couldn't use the phparmory XML parser, sadly it had a bug with XML attributes. But i found another one that worked properly and nearly the same.

Last edited by zork : 07/10/07 at 6:34 AM.


Offline
Reply With Quote
Old 07/10/07, 12:56 PM   #15
Coeus
Von Kaiser
 
Coeus's Avatar
 
Blood Elf Paladin
 
Kilrogg
Originally Posted by zork View Post
p.s. I couldn't use the phparmory XML parser, sadly it had a bug with XML attributes. But i found another one that worked properly and nearly the same.
What did you end up using? I was starting to use phpArmory, but if it's bugged, I should either look at fixing it or just change to something else.

Offline
Reply With Quote
Old 07/10/07, 2:14 PM   #16
Kallisti
Von Kaiser
 
Kallisti's Avatar
 
Night Elf Druid
 
Ulduar (EU)
I can just recommend antiarcs armory scripts as basis.

http://wow.tachyonsix.com/armory/
http://svn.digitalsentience.com/svn/armory/

Especially:
http://svn.digitalsentience.com/svn/armory/_armory.php

You can remove some code (which is only used for some special functions of his scripts) and edit it to fit your needs, but I found it to be perfect to build some websites quickly.

I'm using some lines of it in the script which generates our memberlist (http://pernoctem.de/members.php) twice a day automatically via cron jobs.

Offline
Reply With Quote
Old 07/11/07, 5:58 AM   #17
zork
Don Flamenco
 
zork's Avatar
 
Dwarf Warrior
 
Eredar (EU)
@Coeus
phpArmory bugged for me so I switched to another parser.

@Kallisti
I don't know if the scripts from antiarc require php5.0 which some web-server don't have. (simplexml is 5.0 only)


Offline
Reply With Quote
Old 09/24/07, 4:42 AM   #18
Hung_war3
Glass Joe
 
Orc Shaman
 
<HOL>
Wildhammer
Originally Posted by D1g1talS0ul View Post
I use cURL to pull down the xml and simplexml to parse it for my guilds roster page. Requires PHP5, which most webhosts haven't switched to (including our host). I run the script below on my desktop that has PHP5, it parses the info I need and puts it into a mysql database at our host. Then on our hosts server with PHP4, roster.php parses the data from the mysql database.

#!/usr/bin/php
<?php

class roster_gen {

 const 
BROWSER="Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.2) Gecko/20070319 Firefox/2.0.0.3";

 public 
$query;
 public 
$server;
 public 
$guild;
 public 
$guildie;
 public 
$page;

public function 
__construct $query$server$guild$guildie$page ) {
    
$this->query $query;
    
$this->server $server;
    
$this->guild $guild;
    
$this->guildie $guildie;
    
$this->page $page;
 } 
// end of __construct()

public function pull_xml() {

    if( 
$this->query === 'roster' ){
        
$url 'http://armory.worldofwarcraft.com/guild-info.xml?r=' $this->server '&n=' $this->guild '&p=' $this->page;
        
      }elseif( 
$this->query === 'character' ){
        
$url 'http://armory.worldofwarcraft.com/character-sheet.xml?r=' $this->server '&n=' $this->guildie;
        
        }

    
$ch curl_init();
    
curl_setopt ($chCURLOPT_URL$url);
    
curl_setopt ($chCURLOPT_RETURNTRANSFER1);
    
curl_setopt ($chCURLOPT_CONNECTTIMEOUT15);
    
curl_setopt ($chCURLOPT_USERAGENT,  roster_gen::BROWSER);
    
    
$url_string curl_exec($ch);
    return 
simplexml_load_string($url_string);
    
    
curl_close($ch);
 } 
// end of pull_xml()

// end class

// query, realm, guild, guildie, page
// query can be roster or character
$roster = new roster_gen (rostercenariusinsurrectionNULL1);

$xml_roster $roster->pull_xml();
$battlegroup $xml_roster->guildInfo->guild['battleGroup'];
$num_guildies $xml_roster->guildInfo->guild->members['memberCount'];

$roster->query=character;
$name 'someguildie';  //change to character you'd like to lookup
$roster->guildie=$name;
$xml_char $roster->pull_xml();

$tree1 $xml_char->characterInfo->characterTab->talentSpec['treeOne'];
$tree2 $xml_char->characterInfo->characterTab->talentSpec['treeTwo'];
$tree3 $xml_char->characterInfo->characterTab->talentSpec['treeThree'];
            
$lastLOGIN =  $xml_char->characterInfo->character['lastModified'];
            
$title =  $xml_char->characterInfo->character['title'];

echo 
"Guild:$roster->guild Realm:$roster->server Battlegroup:$battlegroup\n";
echo 
"Name:$name($title), Talents:$tree1/$tree2/$tree3 Last Login: $lastLOGIN\n";
?>
If you do a var_dump($xml_char) or var_dump($xml_roster) you'll see all the options you can pull from the armory.

Hope this is helpful.
I have got this error when use this form :

Fatal error: Call to undefined function curl_init() in C:\wamp\www\phpArmory\character.php on line 31
Can you help me ? I think this function is not valid right ?

Offline
Reply With Quote
Old 09/24/07, 6:13 AM   #19
Ronnie
Glass Joe
 
Tauren Warrior
 
Vek'nilash (EU)
Originally Posted by Hung_war3 View Post
Can you help me ? I think this function is not valid right ?
You will need libcurl for this and you will also need to compile PHP with the --with-curl=X directive, where X is the location of libcurl's libraries and includes.

If you can't or do not want to use cURL you have to fsockopen() and construct the GET request yourself. Zork posted an example of how to do this: http://dm.next-gen.org/files/search_xml_example_fr.html

Last edited by Ronnie : 09/24/07 at 6:23 AM.

Offline
Reply With Quote
Old 07/22/08, 5:31 PM   #20
bonkers
Glass Joe
 
Night Elf Druid
 
Vek'nilash
xml vs appengine, and new gear ranking site

I'm using Google AppEngine for my Armory-crawling site. If anyone else is using it, AppEngine's URL fetching ability doesn't let one set the User-agent so only the HTML responses are available. If anyone knows a workaround I'd love to hear it.

Here's my tool, Gear Wishlist that generates a list of potential gear upgrades. It doesn't support power-user tweaking, but it a simple way to eyeball what's out there.

Offline
Reply With Quote
Old 07/22/08, 9:17 PM   #21
Nadiar
Von Kaiser
 
Tauren Druid
 
Blackrock
Originally Posted by bonkers View Post
I'm using Google AppEngine for my Armory-crawling site. If anyone else is using it, AppEngine's URL fetching ability doesn't let one set the User-agent so only the HTML responses are available. If anyone knows a workaround I'd love to hear it.

Here's my tool, Gear Wishlist that generates a list of potential gear upgrades. It doesn't support power-user tweaking, but it a simple way to eyeball what's out there.
This isn't really a great thread for it, but it would be cool to get source code for it when you have something working.

Also, right now "Silver Hand" doesn't seem to work at all (says "Error: Server Error"), but "Silver+Hand" pops up asking me if I want Feral DPS or Tanking, and a couple times it has shown my current gear beyond the popup asking for which feral spec I am. After clicking a spec it then continues to "Error: Server Error"

Offline
Reply With Quote
Old 07/23/08, 2:31 AM   #22
bonkers
Glass Joe
 
Night Elf Druid
 
Vek'nilash
Originally Posted by Nadiar View Post
This isn't really a great thread for it, but it would be cool to get source code for it when you have something working.

Also, right now "Silver Hand" doesn't seem to work at all (says "Error: Server Error"), but "Silver+Hand" pops up asking me if I want Feral DPS or Tanking, and a couple times it has shown my current gear beyond the popup asking for which feral spec I am. After clicking a spec it then continues to "Error: Server Error"
Interesting, I hadn't tested with realm names containing spaces. I'll look into it, thanks for the heads-up!

(The server logs show a lot of errors trying to fetch character sheets from the armory.)

EDIT: I made a trivial change to replace spaces with '+' for the armory url generation and it seems to be working for you now.

Last edited by bonkers : 07/23/08 at 2:42 AM.

Offline
Reply With Quote
Old 07/23/08, 5:16 AM   #23
Furizaa
Somewhat usefull
 
Furizaa's Avatar
 
Worgen Hunter
 
Gul'dan (EU)
After i realized that I'm to dump to recompile PHP with cURL, i come up with this to get the Armory XMLs

$ctx stream_context_create(Array("http" => Array("user_agent" => "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1")));
$charXml = (@file_get_contents(ARMORY_URL.urlencode($name),0,$ctx)); 
Works great until now on Ultionis Sanguinis for Member-Pages and Item-Tooltips... if you don't use IE, but thats a style problem.

Germany Offline
Reply With Quote
Old 02/11/09, 2:28 AM   #24
inktomi
Glass Joe
 
Undead Warlock
 
Korgath
I did something very similar, but in Java. Now I get "Server is busy. Please try again later." for all my requests. Seems like I got my IP banned.

Just a friendly warning to remember to put a delay between your requests. Don't want to see others getting banned.

realmRanker - an Achievement ranking and tracking system http://www.realmranker.com

Offline
Reply With Quote
Old 02/11/09, 7:59 AM   #25
Trouble
Bald Bull
 
Trouble's Avatar
 
Trouble
Blood Elf Druid
 
No WoW Account
You have to throttle your requests. If you exceed 45 requests in like a minute (or one per 1.5 seconds over a sustained period) you'll start pulling 503's. If you keep hammering after you're pulling 503's then it'll ban you for a day or so. It only lasts for a day or so, but it's your warning.

United States Offline
Reply With Quote
Reply

Go Back   Elitist Jerks » Public Discussion

Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
The Warcraft Armory Nite_Moogle Public Discussion 336 06/29/07 4:46 PM
Unpopular talents, or the Armory in action Navaash Public Discussion 303 05/16/07 1:24 AM
In Game Armory Mod Maligne User Interface and AddOns 29 05/07/07 11:37 AM
[All Classes] Armory data used to see 31 and 41 pt talent use. Nomad_Wanderer Class Mechanics 2 05/03/07 11:23 AM