Get a Page Like a Mobile User

Some sites will serve different content to mobile and desktop users, like Wikipedia. It redirects mobile users to en.m.wikipedia.org.

That might prove helpful in some scraping scenarios, such as targeted content or faster response due to fewer resources. Whatever reason you have to scrape as a mobile user, two main things matter: window size and user agent (suggested with other headers). We support both.

Window Size

To set the concrete window size, you'll need to send the request with Javascript Rendering. That will allow the browser to use the size you want, and the target site will read from there.

You'll need to add three parameters:
  • js_render to true
  • window_width with the number of pixels wide you want the screen to be
  • window_height same for the height

To simulate iPhone 6 that is 414x736 pixels.

curl "https://api.zenrows.com/v1/?apikey=YOUR_KEY&url=YOUR_URL&js_render=true&window_width=414&window_height=736"

User-Agent

The second part is to send a Custom Header called "User-Agent". Browsers use it to identify themselves, as do some HTTP clients (i.e., cURL).

User-Agents are long strings that often change since they contain browser and system versions. The best idea is to look for actual User-Agents and copy them.

We'll see another example using cURL. This one will need a param custom_headers set to true and a -H modifier for the cURL command. What comes was copied directly from a real User-Agent to avoid sending something wrong.

curl \ 
-H "User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1" \ 
"https://api.zenrows.com/v1/?apikey=YOUR_KEY&url=YOUR_URL&js_render=true&window_width=414&window_height=736&custom_headers=true"

You can test headers and parameters in our Builder. It will also output code in several languages.

Mobile Emulation from Builder

As we said above, sending only the User-Agent might be disadvantageous in some cases. When trying to bypass efficient anti-bot systems, modifying this header by hand might raise a red flag. The reason is that browsers tend to send several headers together and with a specific value for some of them. That means it might send an iPhone User-Agent with another header that only comes with desktop Chrome.

If you find any trouble with that, contact us, and we'll help you set up your calls like a mobile user.