이상한 HTTPS 형태로 기계화하십시오
-
18-09-2019 - |
문제
나는 대학에서 간단한 양식을 검색하려고 노력하고 있습니다. 기계화. 코드는 Google 검색에 적합하지만 결과에서 검색 양식을 반환합니까? 나는 정말로 혼란스러워. 어떤 충고? 감사!
ruby script/console
require 'mechanize'
agent = WWW::Mechanize.new
agent.get("https://www.owens.edu/cgi-bin/class.pl/")
agent.page.forms
form = agent.page.forms.last
form.occ_subject = "chm"
form.submit
해결책
나는 그것을 해결했다! 언제 form.submit
마지막 버튼을 가정합니다. form.buttons
사용하는 버튼입니다. 마지막 버튼 form.buttons
고급 양식을위한 것이므로, 더 포괄적 인 고급 검색 양식이지만 결과 페이지 객체는 다른 형태입니다.
require 'mechanize'
agent = WWW::Mechanize.new
agent.get("https://www.owens.edu/cgi-bin/class.pl/")
agent.page.forms
form = agent.page.forms.last
form.occ_subject = "chm"
result = agent.submit(form, form.buttons.first)
result.parser.css('table.cs-table-settings tr.tbl-class-fill-b td font b').map { |v| v.text.strip }
=> ["Principles of Chemistry", "Principles of Chemistry", "Principles of Chemistry", "Principles of Chemistry", …]
마침내 우리는 그것의 바닥에 도착합니다! HTML은 끔찍하므로 XPATH 모자를 착용해야합니다! :)
제휴하지 않습니다 StackOverflow