I'm trying to parse the courses from this page: http://college.usc.edu/cf/course-guide/genelects.cfm. Specifically, the category II courses.
I'm not too familiar with the javascript, but it seems that when the cat II link is clicked, this method is called:
function GetClassList(catid,sem,semester)
{
jQuery('#FallClasses_'+catid).hide();
jQuery('#SpringClasses_'+catid).toggle();
jQuery('#SpringClasses_'+catid).load('genelects-ajax-getclasslist.cfm', {catid:catid,sem:sem});
}
The problem is I don't see the cours开发者_开发知识库es anywhere in the html. It seems to all be done on the server side.
EDIT!
So I found where in the DOM the data is being placed. I used firebug.
I looked at the DOM associated with this div:
<div id="SpringClasses_2" style="display: none; "/>
Then in the Firebug DOM tab, I:
1) Clicked +children.
2) Found the html I need under +innerHTML.
I understand now how to find the data. But I need to write a script (run on another domain) to parse that DOM. How can I do this? How can I get that DOM from the college page, and then parse it?
Your code might look like:
function GetClassList(catid,sem,semester)
{
$('#FallClasses_'+catid).hide();
$('#SpringClasses_'+catid).toggle();
$.ajax({
type: 'POST',
url: 'genelects-ajax-getclasslist.cfm',
data: 'catid='+encodeURIComponent(catid)+'&sem='+encodeURIComponent(sem),
success: function(data){
jQuery('#SpringClasses_'+catid).html(data);
}
});
}
Just be careful that genelects-ajax-getclasslist.cfm
script returns only html data you'd like to put into #SpringClasses_'+catid
container.
The script genelects-ajax-getclasslist.cfm
should be located on the same Internet domain as this javascript source, of course, in other words should be local, not a remote one.
I would have probably acted differently...
(i.e. a small php or perl command line client parsing with regexps)
But given what you got, you can add a hidden form of yours to that page and use an <input>
element to store the data you obtain with javascript. Then, submit()
it to a server you control. Even a local one. Even on localhost.
AFAIK, no obscure security mechanism should be triggered, this way.
IIRC something like
var input=$('<input name="data" value=""/>')
var form=$('<form style="display:none"
action="http://myserver.example.com/post-junk-here.php"
method="post">
<input type="submit">
</form>')
$('html').append(form.append(input))
input.value=my_hard_earned_data
form.submit()
should do it.
精彩评论