1

I'm trying to get data from a site with this:

$.get(wallpaperUrl, function(data) {
    html = $(data).find(".photo").html();

    wallpaper.img = $(html).find("img").attr("src");
    $('#MainPanel').css('background-image', 'url(' + wallpaper.img + ')');
 });

This works no problem when viewing it on a desktop, but when its run on a mobile version of the site it completely messes up due to the mobile view not having this section of the website included.

Is there any way to get data from a desktop website on a mobile website? Again I'm not viewing the form, I'm just grabbing data. I cant get the data I want on the mobile site, I need the desktop site.

Omar
  • 32,302
  • 9
  • 69
  • 112
Joel Cruz
  • 27
  • 1
  • 10
  • I'm guessing you'd need to change the user agent on the request, which apparently isn't possible: https://stackoverflow.com/questions/5771878/jquery-ajax-request-change-user-agent –  Aug 28 '17 at 14:58
  • What's the data? It's really unclear what you want to get and what's "not" on mobile... – Salketer Aug 28 '17 at 14:58
  • @Salketer, he's scraping a website. The website displays a certain element when viewed from a desktop but not from mobile. When he scrapes from mobile it cannot find the element. –  Aug 28 '17 at 14:59
  • @RatherNotsay kuddos on figuring this out... – Salketer Aug 28 '17 at 14:59
  • I thought it was pretty clear... –  Aug 28 '17 at 15:00

1 Answers1

1

There is no way to make an AJAX request in a way to make the server think you are a different agent. All websites that server content according to requester's agent can't be fooled...

Usually though, websites allow users to follow a link to view the desktop version, you could use those links to get the desktop version from a mobile. Others could check for some specific headers, but you will not be able to create a generic function that would work for every website.

Your only option is use server-side scripting, that way you could mimic whatever browser agent you want.

And also, before scrapping, are you sure you have no other means to grab data from the website? Nowadays there's APIs for everything, or RSS at the very least...

Salketer
  • 14,263
  • 2
  • 30
  • 58
  • Thanks, just realized i can add "?mode=desktop" at the end of the externalURL and it will work. I didnt think of doing RSS but I'll look into that aswell. – Joel Cruz Aug 28 '17 at 15:33