I have list of hosts and want to get homepage URL of them. The variable location that exist in header html sometime return URL and in the most case the parameter not set.For example the URL "http://www.sharif.ir" don't have location parameter and the home page is "http://www.sharif.ir/home". How I get homepage URL from host URL ? Thank you

有帮助吗?

解决方案

Your case seems to be a treasure hunt game. Follow the clues:

  • http://www.sharif.ir returns HTTP 200, and the page contains an automatic html redirection (meta http-equiv=refresh) to page /c (http://www.sharif.ir/c)
  • http://www.sharif.ir/c returns HTTP 302, which redirects to http://www.sharif.ir/c/portal/layout
  • http://www.sharif.ir/c/portal/layout returns HTTP 302, which redirects to http://www.sharif.ir/home

Welcome to your destination ! :)

At first, tou need to parse for the meta refresh tag in the result header of the first page to get the location (content attribute : url=<relative path>).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top