Page 1 sur 1
[..] Afficher une partie d'une page web
Posté : jeu. 09 avr. 2009 23:04
par nomdutilisateur
Bonjour, j'utilise le code suivant pour afficher une page web qui contient les dernières news dans ma gui :
► Afficher le texte
Code : Tout sélectionner
Func NEWS()
GUICtrlCreateGroup("News", 185, 240, 390, 85)
Dim $oIE, $GUIActiveX
$oIE = _IECreateEmbedded ()
$GUIActiveX = GUICtrlCreateObj($oIE, 188, 253, 384, 71)
If $ARCHLORD_LOCALISATION = "English" Then
_IENavigate ($oIE, "http://arc....hlordgame.com/launcher/right.php?territory=EnglishUK")
EndIf
If $ARCHLORD_LOCALISATION = "French" Then
_IENavigate ($oIE, "http://arc....hlordgame.com/launcher/right.php?territory=French")
EndIf
If $ARCHLORD_LOCALISATION = "German" Then
_IENavigate ($oIE, "http://arc....hlordgame.com/launcher/right.php?territory=German")
EndIf
EndFunc ;==>NEWS
Ce qui donne :
Mais en fait je voudrais plutôt afficher ce qu'il i a un peu plus bas dans la page, sans avoir a utiliser manuellement la scrollbar, l'idéal serait que ça affiche ça :
Donc j'ai rechercher dans l'aide quelque chose qui pourrait supprimer une partie du code html (la partie avec les drapeaux et les titres "News, Link, Date") mais je n'ai rien trouver
J'ai rechercher aussi quelque chose qui pourrai récupérer le lien et la date de la news soit le code :
Code : Tout sélectionner
<td><a href="../news.php?id=9218&skipsplash=true" target="_blank">St Patrick's Day Chantra Sale - Up to 50% OFF</a></td>
<td>Mar 13th 2009</td>
Mais je n'ai pas trouver non plus comment faire pour le recuperer depuis la page et l'afficher dans la gui...
Le code html de la page en question :
► Afficher le texte
Code : Tout sélectionner
<body>
<table>
<tr>
<td width="200" colspan="3"><a href="/launcher/right.php?territory=EnglishUK"><img src="/images/flag_englishuk.gif" style="padding-right:10px;border:0;"></a>
<a href="/launcher/right.php?territory=German"><img src="/images/flag_german.gif" style="padding-right:10px;border:0;"></a>
<a href="/launcher/right.php?territory=French"><img src="/images/flag_french.gif" style="border:0;"></a>
</td>
</tr>
<tr>
<th align=left>News</th>
<th width=200 align=left>Link</th>
<th align=left>Date</th>
</tr> <tr>
<td colspan=3><img src="..//images/divide-small.jpg" alt="divider" /></td>
</tr>
<tr>
<td>[News]</td>
<td><a href="../news.php?id=9280&skipsplash=true" target="_blank">[Notice] Server Maintenance</a></td>
<td>Mar 25th 2009</td>
</tr><tr>
<td>[News]</td>
<td><a href="../news.php?id=9271&skipsplash=true" target="_blank">Player Account System Maintenance - Wednesday 25th March</a></td>
<td>Mar 24th 2009</td>
</tr><tr>
<td>[News]</td>
<td><a href="../news.php?id=9216&skipsplash=true" target="_blank">St Patrick's Day Chantra Sale - Up to 50% OFF</a></td>
<td>Mar 13th 2009</td>
</tr> <tr>
<td colspan=3><img src="..//images/divide-small.jpg" alt="divider" /></td>
</tr>
<tr>
<td>[News]</td>
<td><a href="../news.php?id=9335&skipsplash=true" target="_blank">Easter Fun!</a></td>
<td>Apr 6th 2009</td>
</tr><tr>
<td>[News]</td>
<td><a href="../news.php?id=9218&skipsplash=true" target="_blank">St Patrick's Day Chantra Sale - Up to 50% OFF</a></td>
<td>Mar 13th 2009</td>
</tr><tr>
<td>[News]</td>
<td><a href="../news.php?id=9074&skipsplash=true" target="_blank">Four City Tournament Winners</a></td>
<td>Feb 17th 2009</td>
</tr>
</table>
</body>
Re: [..] Afficher une partie d'une page web
Posté : ven. 10 avr. 2009 03:10
par orax
Je chercherais du côté de _IEPropertySet ou _IEPropertyGet pour récupérer l'élément souhaité. Et peut-être _IETableGetCollection pour récupérer l'élément.
Un exemple avec _IEPropertySet pour supprimer des éléments ; toutefois, je ne sais pas si cette utilisation est "propre" mais ça semble marcher chez moi.
► Afficher le texte
Code : Tout sélectionner
#Include <IE.au3>
$oIE=_IECreate("http://www.autoitscript.fr/forum/index.php")
$obj=_IEGetObjById($oIE,"menubar")
MsgBox(0,"héhé","abracadabra !")
_IEPropertySet($obj, "innerhtml","")
$obj=_IEGetObjById($oIE,"wrapheader")
MsgBox(0,"héhé","abracadabra !")
_IEPropertySet($obj, "innerhtml","")
Avant je faisais ça avec les expressions régulières (mais à mon avais ce n'est peut-être pas une bonne idée).
Donc à mon avis, on pourrait récupérer le contenu du tableau (les cellules <td>)
St Patrick's Day Chantra Sale - Up to 50% OFF + la date avec _IETableGetCollection et récupérer les liens avec _IELinkGetCollection. J'ai fait un test rapide, ça semble aller. Il faudrait essayer de mettre ça en pratique pour voir si ça correspond à vos attentes.
Re: [..] Afficher une partie d'une page web
Posté : dim. 12 avr. 2009 15:15
par Max5
Il est possible de récupérer le lien de la news (plus la description) ainsi que la date par expressions régulière puis écrire le tout dans la fenêtre _IE au moyen de _IEDocWriteHTML().
par exemple :
Code : Tout sélectionner
$regex = StringRegExp($SOURCE_HTML, "(?s)\[News\].*?(<a href.*?</a>).*?<td>(.*?)</td>", 3)
If Not @error Then
$news = ""
For $i = 0 To UBound($regex) - 1 Step 2
$news = $news & "[News du " & $regex[$i+1] & "] : " & $regex[$i] & @CRLF
Next
_IEDocWriteHTML($oIE, $news)
EndIf
J'ai basé ma regex sur le code HTML donné en exemple.
Re: [..] Afficher une partie d'une page web
Posté : mer. 22 avr. 2009 01:25
par nomdutilisateur
Ha merci c'est parfait c'est ce que je chercher (StringRegExp)
J'ai un dernier petit soucis, J'ai tester "InetGet" ça à fonctionné, mais là avec "_IEBodyReadHTML" ce code ne fonctionne pas je ne vois pas ce qu'il cloche
Code : Tout sélectionner
Func NEWS()
GUICtrlCreateGroup("News", 165, 240, 410, 85)
Dim $regex, $news, $SOURCE_HTML, $GUIActiveX, $oIE
$oIE = _IECreateEmbedded ()
$GUIActiveX = GUICtrlCreateObj($oIE, 168, 253, 404, 71)
_IENavigate ($oIE, "http://archlordgame.com/launcher/right.php?territory=EnglishUK")
$SOURCE_HTML = _IEBodyReadHTML($oIE)
$regex = StringRegExp($SOURCE_HTML, "(?s)\[News\].*?(<a href.*?</a>).*?<td>(.*?)</td>", 3)
If Not @error Then
$news = ""
For $i = 0 To UBound($regex) - 1 Step 2
$news = $news & '<font size="2">[' & $regex[$i+1] & "] : " & $regex[$i] & "</font><br />"& @CRLF
Next
_IEDocWriteHTML($oIE, $news)
EndIf
;~ MsgBox(1,'debug_regex',$regex)
;~ MsgBox(1,'debug_SOURCE_HTML',$SOURCE_HTML)
EndFunc ;==>NEWS
Re: [..] Afficher une partie d'une page web
Posté : mer. 22 avr. 2009 03:29
par orax
IE "traite" le code source et vous renvoie un truc différent (entre autre, on se retrouve avec des balises en majuscules). Donc changez l'expression régulière en
(?is)\[News\].*?(<a href.*?</a>).*?<td>(.*?)</td>
Vous pouvez aussi utiliser :
Code : Tout sélectionner
#include <INet.au3>
$SOURCE_HTML = _INetGetSource("http://archlordgame.com/launcher/right.php?territory=EnglishUK")
pour télécharger le code source sans fichier temporaire.