L
L
lemonlimelike2020-07-01 01:07:17
Python
lemonlimelike, 2020-07-01 01:07:17

How to change IP of tor browser in python?

Hello! Faced such a problem that the IP tor browser does not change when parsing. I decided to check what my IP looks like in requests and found such a function.

import requests
from bs4 import BeautifulSoup
import socks
import socket
from time import sleep

def checkIP():
    ip = requests.get('http://checkip.dyndns.org').content
    soup = BeautifulSoup(ip, 'html.parser')
    print(soup.find('body').text)


socks.set_default_proxy(socks.SOCKS5, "localhost", 9150)
socket.socket = socks.socksocket
i = 0
while i <=100:
  i += 1
  checkIP()
  sleep(2)


Of course the IP changes, but only once. How to make the IP change happen every couple of minutes, or with some errors, for example, an error when requesting a site that bans IP.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SKEPTIC, 2020-07-01
@lemonlimelike

Tor as a proxy?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question