![URL 목록에서 URL+제목을 자동으로 생성하는 방법은 무엇입니까? (bash 또는 기타 도구 사용)](https://linux55.com/image/155276/URL%20%EB%AA%A9%EB%A1%9D%EC%97%90%EC%84%9C%20URL%2B%EC%A0%9C%EB%AA%A9%EC%9D%84%20%EC%9E%90%EB%8F%99%EC%9C%BC%EB%A1%9C%20%EC%83%9D%EC%84%B1%ED%95%98%EB%8A%94%20%EB%B0%A9%EB%B2%95%EC%9D%80%20%EB%AC%B4%EC%97%87%EC%9E%85%EB%8B%88%EA%B9%8C%3F%20(bash%20%EB%98%90%EB%8A%94%20%EA%B8%B0%ED%83%80%20%EB%8F%84%EA%B5%AC%20%EC%82%AC%EC%9A%A9).png)
Linux Bash를 사용하는 경우 다음 명령을 사용하여 텍스트 파일을 변환하려면 어떻게 해야 합니까?
http://example.org/
https://en.wikipedia.org/wiki/Main_Page
https://www.youtube.com/watch?v=mGQFZxIuURE
입력하다:
http://example.org/ Example Domain
https://en.wikipedia.org/wiki/Main_Page Wikipedia, the free encyclopedia
https://www.youtube.com/watch?v=mGQFZxIuURE Mike Perry - The Ocean (ft. Shy Martin) - YouTube
또는 다음을 입력하세요:
http://example.org/
Example Domain
https://en.wikipedia.org/wiki/Main_Page
Wikipedia, the free encyclopedia
https://www.youtube.com/watch?v=mGQFZxIuURE
Mike Perry - The Ocean (ft. Shy Martin) - YouTube
?
어떻게 할 수 있습니까?
- 파일의 URL 목록에서 URL을 추출하고,
- 페이지를 로드하고,
- 페이지 제목을 추출하고,
- 같은 줄 또는 바로 다음 줄의 URL 뒤에 페이지 제목을 추가한 다음
목록의 각 후속 URL에 대해 1~4단계를 수행하시겠습니까?
Linux Bash를 사용하지 않는다면 또 무엇이 있을까요?
답변1
curl
헤헤강아지:
while IFS= read -r url
do
printf "%s " "$url"
curl -sL "$url" | # fetch the page
pup 'head title:first-of-type text{}' # get the text of the first title tag in head
done < input