tags:

views:

49

answers:

1

hi,

i have this html code

<div class="name"> 

<span id="businessNumOnMap2" class="resultNumberOnMap" style="display:none;">2</span> 

<span>

<a href="/len/aapproximatch%20search/284096.php" onclick="loadBusinessInfo('1', '284096'); return false;" class="businessName">Bangsar Seafood Garden Restaurant</a></span><span id="phoneSpan1"></span>

<script type="text/javascript">
var d=document.getElementById('phoneSpan1');d.innerHTML+='0';d.innerHTML+='3';d.innerHTML+=0?'8':'-';d.innerHTML+=1?'2':'1';d.innerHTML+='2';d.innerHTML+=1?'8':'1';d.innerHTML+=0?'0':'2';d.innerHTML+='2';d.innerHTML+=0?'4':'5';d.innerHTML+='5';d.innerHTML+=1?'5':'0';
</script> 

</div>

i start my regex with this : <div class="name"[^>]*>[\s\S]+?</div> and i remove the html. im using this : <[^>]*>

how ever, the out put is Bangsar Seafood Garden Restaurant <script type = "text/javascript"> ...</script><div>

the one that i want is on Bangsar Seafood Garden Restaurant..can anyone help me?

A: 

If all you want is the business name, can't you just do a text search for class="businessName" and then take everything between the next > and <. It might not work if the HTML changes, but you run the same risk with Regex.

ho1
thnks..it works just perfect..can i ask something??..how to make my application flexible??..how to ensure that the codes that i use still can be use eventhough the HTML code changes?.
akmalizhar
@akmalizhar - no problem. You can't really make it work at all times unless you can limit the changes to the input HTML, it would be better to retrieve the data in a well defined XML format or similar. However, if you need to continue using HTML you might want to look at the HTMLAgilityPack, I've never used it myself but I've seen it recommended for parsing HTML.
ho1