Bonjour à tous et à toutes.
je cherche a extraire tous les hyperliens d'une page web. Je me sers donc de cette petite regexp sympathique
(<a[^<>]*?href=["\'](.+?)["\'].*?>(.*?)</a>)|(<form[^<>]*?action=["\'](.+?)["\'].*?>)|(<area[^<>]*?href=["\'](.+?)["\'].*?>)
Elle fonctionne a merveille mais voila que j'ai un site ou il y a énormément de balise <area ...>
Donc après plusieurs test voici les résultats que je ne comprend pas très bien...
Jusqu'à 7 liens ca marche
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| <area shape="poly" coords="..." href="lien1.html" title="title1">
<area shape="poly" coords="..." href="lien2.html" title="title2">
<area shape="poly" coords="..." href="lien3.html" title="title3">
<area shape="poly" coords="..." href="lien4.html" title="title4">
<area shape="poly" coords="..." href="lien5.html" title="title5">
<area shape="poly" coords="..." href="lien6.html" title="title6">
<area shape="poly" coords="..." href="lien7.html" title="title7">
pattern : '#(<a[^<>]*?href=["\'](.+?)["\'].*?>(.*?)</a>)|(<form[^<>]*?action=["\'](.+?)["\'].*?>)|(<area[^<>]*?href=["\'](.+?)["\'].*?>)#'
Résultat :
( 0 => '<area shape="poly" coords="..." href="lien1.html" title="title1">'
1 => ''
2 => ''
3 => ''
4 => ''
5 => ''
6 => '<area shape="poly" coords="..." href="lien1.html" title="title1">'
7 => 'article408.html'
) |
Et a 8 ca plante...
1 2 3 4 5 6 7 8 9 10 11 12
| <area shape="poly" coords="..." href="lien1.html" title="title1">
<area shape="poly" coords="..." href="lien2.html" title="title2">
<area shape="poly" coords="..." href="lien3.html" title="title3">
<area shape="poly" coords="..." href="lien4.html" title="title4">
<area shape="poly" coords="..." href="lien5.html" title="title5">
<area shape="poly" coords="..." href="lien6.html" title="title6">
<area shape="poly" coords="..." href="lien7.html" title="title7">
<area shape="poly" coords="..." href="lien8.html" title="title8">
pattern : '#(<a[^<>]*?href=["\'](.+?)["\'].*?>(.*?)</a>)|(<form[^<>]*?action=["\'](.+?)["\'].*?>)|(<area[^<>]*?href=["\'](.+?)["\'].*?>)#'
Pas de match |
Quelqu'un pourrait m'expliquer pourquoi et s'il y a un moyen de pallier ce problème ?
Partager