0

Im using Simple HTML DOM to scrape a Javascript file like this:

$html = file_get_html('http://www.The-Javascript-File.js');
echo $html;

The problem is that I get this error in console:

Resource interpreted as Script but transferred with MIME type text/html: http://www.The-Javascript-File.js

Obviously because its a HTML parser('file_get_html')...Is there something I can do with Simple HTML DOM to get the file as a proper js file?

4
  • If the remote URL is a script (and not an HTML page) do you really need to be using Simply HTML DOM? Why not just do $contents = file_get_contents('The-Javascript-File.js')? Commented Aug 16, 2013 at 19:12
  • Wait .. what .. why are you trying to read a JavaScript as HTML? If you just want the file user file_get_contets? Commented Aug 16, 2013 at 19:12
  • Wait, why you are using that instead of just a file_get_content? Commented Aug 16, 2013 at 19:13
  • Because Im stupid, thank you guys:) I totally forgot about file_get_content Commented Aug 16, 2013 at 19:17

1 Answer 1

1

SimpleHTMLDom, as the name indicates is for parsing HTML, not JavaScript. If you want to parse JavaScript, then why not simply use file_get_contents()?

$js = file_get_contents('http://www.example.com/file.js');
//parse it!

There's also UglifyJS (originally based on parse-js). You may want to check that out, as well.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.