-1

I'v been trying to make a script that checks reddit page and sends back titles of posts. I am able to use

$( "#foo" ).load( "https://www.reddit.com/r/csgobetting/search?q=flair%3Amatch&sort=new&restrict_sr=on&t=all&feature=legacy_search #siteTable .thing .title a:even" )

but I have to use chrome extension and I want to avoid it at all costs. (It gives me No 'Access-Control-Allow-Origin' header is present error in console)

other thing I tryed is

$.ajax({
    url: "https://www.reddit.com/r/csgobetting/search?q=flair%3Amatch&sort=old&restrict_sr=on&t=all&feature=legacy_search",
    jsonp: "callback",
    dataType: "jsonp",
    success: function(data){
        data=$(data).find('#siteTable > div.thing.id-t3_3m2ezw.linkflair.linkflair-match.odd.link.self > div.entry.unvoted > p.title > a ');
        $('#foo').append(  data );
    }
});

But it gives me error:

Refused to execute script from 'https://www.reddit.com/r/cs...' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

I'v looked on the internet for 3 hours but couldnt find anything that would help me.

Also this is not duplicate to this post as it didint help me.

My goal is to get page titles with links without using extensions or security disabling parameters.

Community
  • 1
  • 1
Einaras
  • 21
  • 4
  • *"My goal is to get page titles with links without using extensions or security disabling parameters"* Good luck. this simply isn't possible using just the browser without extensions or disabling security protocols. – Kevin B Sep 25 '15 at 20:41
  • @KevinB it's possible , i already gave him the answer – Diptox Sep 25 '15 at 21:07
  • @Diptox from my comment: *"using just the browser"* – Kevin B Sep 25 '15 at 21:08
  • @KevinB I havent said "using just the browser", I jsut didint want to disbale security parameters or install extentions, everything else is fine. My goal was to make a script that I can share with people without having them install or change bs – Einaras Sep 25 '15 at 21:14
  • I know, i said that, so that i can make the point in my comment. I think it would be too broad to have the question open to server-side solutions too unless you narrow it down to a specific server-side language. – Kevin B Sep 25 '15 at 21:16

1 Answers1

-2

Best way is cURL , download the HTML content of an URL then ECHO it to your javascript then get what you want :D , or do all of it in PHP with this great PLUGIN : https://code.google.com/p/phpquery/wiki/Selectors

Diptox
  • 1,809
  • 10
  • 19
  • I'v never worked with PHP, so I dont know how it would go.. :( – Einaras Sep 25 '15 at 20:22
  • give me 5 min i will make for you a link that if you give it a parameter URL , it will return the HTML code , hope it helps you 5min be right back – Diptox Sep 25 '15 at 20:25
  • do you have a server where to host the file ? – Diptox Sep 25 '15 at 20:28
  • So here is the Demo LINK http://mouadhhsoumi.tk/stackoverflow/downloadHTMLcontent/getHTML.php?url=YOUR_URL here is a dropbox file link to put it in your server :https://www.dropbox.com/s/pgaug9wuq2o2meb/getHTML.php?dl=0 – Diptox Sep 25 '15 at 20:33
  • Okay, thanks. I will try to make something out of it. I hope it works. Gonna leave this open so others can brainstorm when I test things, but i think it will solve it! – Einaras Sep 25 '15 at 20:40
  • it works i tested it , here is the link that you gave in your post open it and you will see the full page :D http://mouadhhsoumi.tk/stackoverflow/downloadHTMLcontent/getHTML.php?url=https://www.reddit.com/r/csgobetting/search?q=flair%3Amatch&sort=new&restrict_sr=on&t=all&feature=legacy_search #siteTable .thing .title a:even – Diptox Sep 25 '15 at 20:43
  • It does load the page, but for some reason when i try to load that page thru ajax, it gives me `Uncaught SyntaxError: Unexpected token <` – Einaras Sep 25 '15 at 20:46
  • don't use jsonp remove those 2 lines from your ajax request : jsonp: "callback", dataType: "jsonp", – Diptox Sep 25 '15 at 20:51
  • Yeah tryed that.. `No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.` – Einaras Sep 25 '15 at 20:52
  • ah sorry i forget to active cross domain :p :p 1sec i fix that – Diptox Sep 25 '15 at 20:54
  • I added `header('Access-Control-Allow-Origin: *');` and it seem to fixed the error, im trying to get it working now, as it doesnt change anyhitng yet – Einaras Sep 25 '15 at 21:03
  • that's nice , hope you are ok now :D – Diptox Sep 25 '15 at 21:05