在JavaScript /浏览器中处理网页并插入数据库?

I'm processing URLs with my program,

Basically what it does is, file_get_contents($url) to get web content and attach a JavaScript code at the bottom which processes the HTML source for the biggest image and inserts into the database by ajax.

The problem is I have to instantiate Firefox browser for the processing. I really don't need Firefox to render the page visually and other workings. All I want is for my script to do its job.

So is there a way to use Firefox's HTML/CSS and JavaScript engine without having to call the entire browser?