Ruby crawling specific url only.

Asked 2 years ago, Updated 2 years ago, 81 views

I'm practicing web crawling using nokogiri.

http://news.naver.com/main/read.nhn?mode=LSD&mid=shm&sid1=103&oid=001&aid=0008639625 I want to pick the title of Naver News, but if I run the ruby file, the result will not come out and there will be no response.

Even if I bring the url to wget, it only says Connecting to news.naver.com (news.naver.com) and the result does not come out. Other urls have no problem with code, but only Naver news doesn't work. I wonder why.

And I'm curious about the solution.


#encoding utf-8
require 'nokogiri'
require 'open-uri'


url="http://news.naver.com/main/read.nhn?mode=LSD&mid=shm&sid1=103&oid=001&aid=0008639625"
page = Nokogiri::HTML(open(url))
title = page.search("title").text
puts title



nokogiri ruby crawling

2022-09-22 20:34

1 Answers

When I turned the attached code, I can print out the title well. Check if the internet is not working.


2022-09-22 20:34

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.