0

I wrote a small script for scraping some data. Unfortunately i get blocked after a certain amount of requests. Since i have a VPN client running (VPNExpress & Mac) i make a manual reconnect to the VPN client, get a new IP and keep scraping.

Is there any simple way to force my client to reconnect on its own out of a python script? E.g. turn WiFi off and on again:

import os os.system("networksetup -setairportpower airport off") os.system("networksetup -setairportpower airport on")

Thought there is maybe a better way to do this? Like "blocking" the connection to force the vpn client to reconnect?

RandomDude
  • 1,101
  • 18
  • 33

1 Answers1

0

Use try except to see when the requests fail. On fail, try switching off your wifi, and then switch on and then wait for x amount of time before checking your ip address. If ip address isn't available, wait more until you get one. Once you get ip address, carry on scraping.

Community
  • 1
  • 1
kawadhiya21
  • 2,458
  • 21
  • 34