Struggling to make a script to download vpn's from site work

Post your questions about VPN Gate Academic Experiment Service here. Please answer questions if you can afford.
Post Reply
samsepi0l
Posts: 1
Joined: Tue Apr 04, 2017 1:33 pm

Struggling to make a script to download vpn's from site work

Post by samsepi0l » Tue Apr 04, 2017 1:41 pm

I've been using vpngate.net for sometime and I decided to make a script that deletes all the .ovpn files in the current directory, runs a python script that downloads a new file and runs it.
My problem occurs in this python script. I use web scraping to download the homepage (http://vpngate.net), then it selects all vpn's download urls, stores them in a list and chooses one randomly. Everything's fine until here. The problem is that, every time I open "http://vpngate.net/en/[choosen_vpn]" it redirects to the homepage.
What can I do to solve this?

Code here for anyone interested:

import requests
from bs4 import BeautifulSoup
from random import randint
import time
import sys
import webbrowser

url = "http://vpngate.net"
print("[+] Connecting to vpngate.net...")
page = requests.get(url)
if page.status_code == 200:
print("[+] Connection established.")
else:
print("[-] Connection went wrong\nQuiting.")
time.sleep(1)
sys.exit()

soup = BeautifulSoup(page.content, "html.parser")

open = []
print("[+] Sorting vpn's...")
for link in soup.find_all("a"):
if "do_openvpn" in str(link):
open.append(str(link["href"]))

print("[+] Choosing random vpn...")
number = randint(0, len(open))

print("\n[+] Connecting to vpn's url...")
page2 = requests.get(url + "/en/" + open[number])
soup2 = BeautifulSoup(page2.content, "html.parser")
print("[ ] Checking if url didn't redirect to homepage...")
while soup2.find_all("title")[0] == soup.find_all("title")[0]:
print("[-] Url redirected to homepage.")
print("[+] Trying again...")
number = randint(0, len(open) - 1)
page2 = requests.get(url + "/en/" + open[number])
soup2 = BeautifulSoup(page2.content, "html.parser")

webbrowser.open(url + "/en/" + open[number])

Post Reply