qadeer_ahmad wrote:Is there any perfect solution of this issue?
Yep: don't do it. :p
To elaborate, "scraping" data is a very crude way of getting the information you want from a remote source and, as you've pointed out, can easily be broken by even the smallest of design changes. This is why you should make every feasible effort into using some sort of XML feed to query the remote server for the information you want.
If that fails, the first thing you should realize is that many websites explicitly state that any automated access/retrieval/storage/use of the information on their site is prohibited (e.g. by an AUP or something similar).
If that isn't true, and you're still left with no other option that retrieving the HTML source code displayed and scanning it for data, you might look into using [man]DOM[/man] to navigate to a specific point in the HTML document and retrieve the data. In theory, this kind of solution would be more resilient to slight design changes since it doesn't rely on preg_match() to search for specific HTML markup.