기본 검색에서 돌아온 모든 페이지의 모든 Uni 이름을 표시하기 위해 UCAS 웹 사이트에서 데이터를 긁어 내려고했습니다. 이것은 내 코드모든 검색 결과 페이지의 정보를 모으는 데이터
"The University of Aberdeen
Abertay University
Aberystwyth University
ABI College
Abingdon and Witney College
The Academy of Contemporary Music
Access to Music
Accrington & Rossendale College
Activate Learning (Oxford, Reading, Banbury & Bicester)
The College of Agriculture, Food and Rural Enterprise
Amersham & Wycombe College
Amsterdam Fashion Academy
Anglia Ruskin University
Anglo European College of Chiropractic
Arden University (RDI)
University of the Arts London
Arts University Bournemouth (formerly University College)
ARU London
Askham Bryan College
Aston University, Birmingham
Availability
Applying through Extra
Single/Combined subjects
Provider types
How you study
Qualification level
Conservatoire specialism"
입니다 : 아래 볼 수 있듯이
지금까지, 루프 작동하지 않고, 그것은 페이지 하나뿐만 아니라 어떤 임의의 정보의 모든 대학의 이름을 표시
require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'mechanize'
mechanize = Mechanize.new
doc = mechanize.get('http://search.ucas.com/')
form = doc.forms.first
form['Vac'] = '2'
form['AvailableIn'] = '2016'
doc = form.submit
doc.search('li.results clearfix').each do |h3|
puts h3.text.strip
while a = doc.at('div.pagerclearfix a')
doc = Nokogiri::HTML(open(a[:href]))
doc.search('results clearfix').each do |h3|
puts h3.text.strip
end
end
end
정확히 무엇이 문제입니까? 모든 페이지가 아닌 첫 페이지의 결과 만 표시됩니까? – mlovic
그래, 첫 번째 puts가 인쇄되고 루프가 제대로 작동하지 않는 것 같아요. div.pagerclearfix a와 관련된 문제는 페이지를 검사 할 때 pager.clearfix라고 불리는 것 같습니다. – Akamaru
안녕하세요. "[mcve]"를 읽으십시오. 질문 자체에 최소한의 HTML 샘플이 필요합니다. 도움을 요청하려는 일부 사람들은 인터넷에 접속할 수 없거나 문제의 태그를 찾기 위해 큰 파일을 탐색하려고하지 않을 것입니다. –