0

So I am trying to work on my python project that I have no idea about. So, there is this website whose domain name is constantly changing for some issues. For example, for a few days it'll be 'example.kr' and suddenly it'll change to 'example.in'. When I go to 'example.kr' after it has been removed, I won't be redirected to the new website. However, when I connect to the main address of the website that is "example.com" it automatically redirects to the current domain 'example.in'. But the problem here is, I cannot connect to the main website ( which will redirect me to the new domain) without a proxy or a VPN. So I would appreciate if someone could give me ideas on how to make a python script that will access the main website with a proxy ( which I have) and return the current domain name.

I don't know if I made it clear, but if not, please feel free to ask me.

thanks.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • What kind of proxy are you using? You can setup a Python script to start the proxy before hitting the main url. – Sam Chats Sep 07 '19 at 07:24
  • @SamChats Yes, i could do that, but how do i share my product with someone who does not have the proxy installed? i want to embed the proxy in the code so that it'll automatically open the website with the given proxy. – Shockhandler Sep 07 '19 at 07:30

1 Answers1

0

Using the requests library, you can set up a proxy https://2.python-requests.org/en/master/user/advanced/#proxies, I'll use a simple HTTP proxy for this demo but SOCKS can also be used. Then you can check for something like a 301 or 302 redirect, since that sounds like what might be happening. I'll use http://google.com as an example, it should return a 301 to the WWW subdomain (http://google.com -> http://www.google.com)

Borrowed and updated some code from a different question: Python Requests library redirect new url

import requests

proxies = {'http': 'http://user:pass@10.10.1.10:3128/'}  # Example proxy with basic auth from docs

response = requests.get("http://google.com", proxies=proxies)

if response.history:
    print("Request was redirected")
    for resp in response.history:
        print(resp.status_code, resp.url)
    print("Final destination:")
    print(response.status_code, response.url)
else:
    print("Request was not redirected")

Returns

Request was redirected
301 http://google.com/
Final destination:
200 http://www.google.com/
jamd315
  • 18
  • 4