최신 게시물에서 소스 HTML 코드를 얻으려고 하는데...
이 URL:
http://www.sportsbookreview.com/forum/search.php?do=getnew
다음으로 리디렉션:
http://www.sportsbookreview.com/forum/search.php?searchid=26505884
최신 게시물을 찾을 수 있는 곳
cURL을 사용하여 최종 URL을 얻는 방법은 무엇입니까?
내가 사용하는 경우:
curl -s http://www.sportsbookreview.com/forum/search.php?do=getnew > $shDir$urlLatestPosts
그러면 내가 찾고 있는 페이지가 아닌 다른 페이지가 표시되는데, 최종 URL을 얻을 수 있는 방법이 있나요?
답변1
사용 curl -L
. 매뉴얼에서:
-L, --location
(HTTP/HTTPS) If the server reports that the requested page has moved to a different location (indicated with a Location: header and a 3XX response code), this option
will make curl redo the request on the new place. If used together with -i, --include or -I, --head, headers from all requested pages will be shown. When authentica-
tion is used, curl only sends its credentials to the initial host. If a redirect takes curl to a different host, it won't be able to intercept the user+password. See
also --location-trusted on how to change this. You can limit the amount of redirects to follow by using the --max-redirs option.
When curl follows a redirect and the request is not a plain GET (for example POST or PUT), it will do the following request with a GET if the HTTP response was 301,
302, or 303. If the response code was any other 3xx code, curl will re-send the following request using the same unmodified method.