2016-07-31 4 views
0

UCAS 웹 사이트 (mechanicalize gem 사용)에서 많은 데이터를 긁어 내고 대부분 작동하지만 스코틀랜드에서 Entry Requirements를 가져 오려고하면 문제가 발생합니다. 아래는 입력 요구 사항을 찾아서 긁어내는 데 사용 된 코드입니다.레일 데이터 메이스 쿼리/클리닝 결과를 기계화합니다

 entry_link = course_details.search('ul.details_tabs a').first 
     if entry_link 

     # If there is a link to a qualification page for the course go to that 
     details_info[:entry] = process_entry(@mechanize.get(entry_link["href"])) 
     end 
end 


def process_entry(entry_req) 
    entry_array = [] 
    entry_info = {} 

     # Sets all data in hash 
     @requirements = entry_req.search('li.qual-element.qual_range').text.strip 
     entry_info[:req]   = @requirements 

     #Pushes to array, and prints  
     entry_array.push(entry_info) 
     print_entry_info(entry_info) 

그러나이 결과가 모두 큰 것은 아닙니다. 오히려 스코틀랜드 highers 또는 고급 highers 중 하나에 대한 하나 개의 결과를 돌려보다가 그들 모두를 끌어와 같은를 출력합니다

BBB Typical offerAABB Typical offer 

가에서 두 영역에 어쨌든 거기 만 BBB 또는 AABB 또는 방식을 당겨 gsub 또는 뭔가를 사용하여 AABB 또는 BBB 만 표시하도록 스트립하십시오. 어떤 도움을 주셔서 감사합니다. 이러한 데이터에서 가져온 것입니다 예를 들어 페이지에

링크 : http://search.ucas.com/course/entryrequirements/448323/anthropology?Vac=2&AvailableIn=2016&IsFeatherProcessed=True&ret=providers#coursedetailsmenu

+0

"[ask]"및 "[mcve]"를 읽으십시오. 우리는 질문 자체에서 문제를 설명하는 최소 코드와 최소 데이터를 볼 필요가 있습니다. –

+0

'course_details.search ('ul.details_tabs a'). 첫 번째는'course_details.at ('ul.details_tabs a')'로 쓰는 것이 더 좋습니다. –

답변

0

문제는 다음과 같습니다

entry_req.search('li.qual-element.qual_range').text 

무엇 search 반환되는 노드 세트로 text를 사용하지 마십시오. NodeSet#textNode#text에 대한 설명서를 참조하십시오.

발견 된 노드를 반복하고 각 노드에서 텍스트를 추출해야합니다. 일반적으로 텍스트 배열을 반환하는 search('some selector').map(&:text)을 사용합니다.