2

This is the algorithm of what I want to do:

 1.Locates flickr links with class' high_res_link and puts them in array [].

 2.Opens flickr link with extension "sizes/h/" 

 3.finds largest photo dimensions on flickr. Then goes to that link. Or if there arent any big enough goes to step 2 and goes to next
array. 

 4. then opens link to download if downloading is enabled. If not goes to step 2 and goes to next array.

 5. Goes to step 2 and goes to next array.

I am trying to write some code that crosses two domains: Tumblr and Flickr.

I have currently written 3 functions with Jquery and Javascript which I want to run on 2 different URLs:

Function #1:

function link_to_flickr() {
var hre = [];
$('.high_res_link').parent(this).each(function(){
  var h = $(this).attr('href') +"sizes/o/";
  hre.push(h);
});
alert(hre[0]);
}

This finds the links on the Tumblr page to the Flickr pages I want. And puts them in an array.

Function #2:

function find_large_quality() {
  var w = 1280;
  var h = 720;
  var matchingDivs = $("small").each(function () {
      var match = /^\((\d+) x (\d+)\)$/.exec($(this).text());
      if (match) {
          if (parseInt(match[1], 10) >= w && parseInt(match[2], 10) >= h) {
              return true;
          }
      }
      return false;
  });
  var href = $.trim(matchingDivs.text()).match(/\(.*?\)/g);

  if (matchingDivs.length >= 1) {
      alert("success");
  } else {
      alert("fail");
  }
 var ho = $('small:contains("'+href[href.length - 1]+'")').parent(this).find("a").attr("href");
alert("http://www.flickr.com"+ho);
}

This function once on the Flickr URL then searches for an image with dimensions greater than 720p.

Function #3:

function Download(){
var heyho = $('a:contains("Download the")').attr('href');
    window.open(heyho, '_blank');
}

This downloads the image file. Once on the Highest quality Flickr URL


Each alert I want to open the URL instead. And perform the next function on. I have been trying for ages and ages of a method to go about doing something like this. Using AJAX, using PHP, using Jsonp, using jquery.xdomainajax.js, etc... But I can't come up with a sufficient method on my own.

Has anybody got any way they would recommend going about doing something like this?

maxisme
  • 3,974
  • 9
  • 47
  • 97
  • What are you trying to do? Could you explain it with few words?! – A. Wolff Jan 13 '14 at 15:42
  • Javascript is typically loaded by the page. Are you somebody who has the ability to modify the javascript of Tumblr AND Flickr? If not, you should probably be programming this in something like Python. – thelr Jan 13 '14 at 16:25
  • @thelr Where can I look to do something like this with Python? – maxisme Jan 13 '14 at 16:29
  • 1
    Well, besides translating your algorithms to Python, you'll want to look at urllib or urllib2 for methods to fetch content from remote URLs. Many usage examples will include methods of parsing data. – thelr Jan 13 '14 at 17:35
  • Can you achieve what you want using the Flickr and Tumblr APIs? This will most likely lead to a cleaner solution. – Ben Smith Feb 18 '14 at 13:04
  • @Fresh It is more kind of the idea behind it rather than the actual outcome. I have made a program that does it using c# and a lot of regex. But that is a bit dull! – maxisme Feb 19 '14 at 00:51
  • if you use APIs, which both sites offer, you won't need to resort to drastic measures to accomplish this simple mash-up. Anything you can use python for in that regard could be done with php. Or you can use tampermonkey to run the JS you already have on each page. You can use a hidden iframe or location.href= to trigger the tampermonkey from inside the page. I think JS is much better suited to scraping than python or php, owing to jQuery, it's powerful DOM, and forging parsers, but i'm sure all are sufficient and opinions vary... – dandavis Feb 19 '14 at 01:06
  • @dandavis But say if I wanted to turn this into an add on or a windows aplication what would I use? I can't believe there isn't yet software that records clicks relative to X paths that you can edit. And then just run it in a for loop! Until you say stop. I can think of so many uses. Surely that is quite an obvious idea. (I feel like there is a big flaw or I am going to be very rich ... [Well not now I have posted it on the internet!]) – maxisme Feb 19 '14 at 01:14
  • 1
    you mean like imacros? – dandavis Feb 19 '14 at 01:16
  • Haha... Awkward. That is awesome. I want to build my own! – maxisme Feb 19 '14 at 01:20
  • I am so excited to check it out when I get home! Shame it is the morning!!!! – maxisme Feb 19 '14 at 01:22

1 Answers1

1

You usually can't run functions on different domains due to CORS unless the domains allow that.

If you're writing a userscript/extension, what you can do is use postMessage (quick tutorial on how to use it cross-domain) on both pages in a content script and use the achieved inter-page communication to control your script flow.

An alternate method is to use the APIs of the websites you want to access.

Or use Python with BeautifulSoup.

Community
  • 1
  • 1
Manishearth
  • 14,882
  • 8
  • 59
  • 76