How to Use Mobile Proxies with Scrapy

Scrapy reads a proxy from the meta of each request, and the built in HttpProxyMiddleware handles the login that is part of the URL. The spider below fetches the IP page and logs the answer.

What do I need before I start?

Hostgw.mobileproxy.live
HTTP and HTTPS port9000
SOCKS5 port9100
Usernamemp4x9q2.mobile.us.sid-a1b2.rot-10
PasswordYOUR_PASSWORD (your own line password)
  • Python 3.9 or newer
  • Scrapy (pip install scrapy)
  • Your username and password in your account under My lines. The username above is an example, and each part is explained in the username reference.

How do I set it up?

  1. Install Scrapy with pip install scrapy.
  2. Save the spider below as ip_spider.py in any folder.
  3. Replace YOUR_PASSWORD with your password.
  4. Run scrapy runspider ip_spider.py and read the logged JSON.
  5. In a project, set the proxy in the request meta, or in a small downloader middleware that adds it to every request.
  6. Lower CONCURRENT_REQUESTS and add a DOWNLOAD_DELAY, so you stay polite to the sites you read.

What does the code look like?

ip_spider.py
import scrapy


class IpSpider(scrapy.Spider):
    name = "ip"

    def start_requests(self):
        proxy = "http://mp4x9q2.mobile.us.sid-a1b2.rot-10:YOUR_PASSWORD@gw.mobileproxy.live:9000"
        yield scrapy.Request("https://ipinfo.io/json", meta={"proxy": proxy})

    def parse(self, response):
        self.logger.info(response.text)

How do I check my IP?

Look for the logged JSON of https://ipinfo.io/json in the output. The ip and country should match your line.

https://ipinfo.io/json

On a mobile line you can ask for a fresh address at any time with your change-IP link, for example https://gw.mobileproxy.live/rotate/k7Qm2xV9. The real link for each line is in your account.

What if it does not work?

The log shows 407 responses.

The login in the proxy URL is wrong. Copy the username again, and percent encode any special characters in the password.

Requests ignore the proxy.

Check that HttpProxyMiddleware is not disabled in your settings and that the meta key is named proxy.

Many timeouts.

Lower the concurrency, raise DOWNLOAD_TIMEOUT, and retry. A mobile line is shared by many phones, so keep the pace moderate.

Frequently asked questions

How do I rotate IPs between requests?

Use a rotating product, which changes the IP per request or per timer. You can also send different session ids in the username.

Should I obey robots.txt?

Yes. Leave ROBOTSTXT_OBEY on in your projects and follow the terms of the sites you read.

Can Scrapy use SOCKS5?

Not natively. Use the HTTP port, or a small local HTTP bridge to SOCKS if you need it.

Related guides

Need a line to connect?

Create an account, top up your balance and your first line is ready to use with Scrapy.

Create account