여기 내 첫 번째 질문은 답을 찾는 데 아주 좋을 것입니다. 나는 노코 기리를 처음 사용합니다.ruby에서 nokogiri를 사용하여 name 속성에 지정된 값이 지정된 웹 사이트의 메타 태그에서 컨텐츠 속성의 내용을 추출 하시겠습니까?
여기 내 문제입니다. 지금, 메타 태그를 통해 실행하는 스크립트를 name 속성 "을 가진 사람을 찾을 싶습니다
<meta content="During my time at TechCrunch I've seen thousands of startups and written about hundreds of them. I sure as hell don't know all ..." name="description"/>
: 나는 (여기 테크 크 런치 게시물) 대상 사이트의 HTML 헤드에 이런 일이 description "을 읽고 내용 속성에있는 내용을 가져옵니다.
내가 속성 이름 설명과 동일 링크를 선택할 수있는 후이
require 'rubygems'
require 'nokogiri'
require 'open-uri'
url = "http://www.techcrunch.com/2009/10/11/the-underutilized-power-of-the-video-demo-to-explain-what-the-hell-you-actually-do/"
doc = Nokogiri::HTML(open(url))
posts = doc.xpath("//meta")
posts.each do |link|
a = link.attributes['name']
b = link.attributes['content']
end
같은 것을 시도 -하지만이 코드는 a와 b에 대한 무기 호를 반환합니다.
나는 posts = doc.xpath("//meta")
, posts = doc.xpath("//meta/*")
등으로 놀았지만 여전히 0입니다.
문서가 구문 분석하지 않는 것처럼 문제는 xpath와 다릅니다. 'puts doc'으로 전체 입력을 포함하고 있지 않은지 확인할 수 있습니다. – akuhn