开发者

Mechanize you different ip

开发者 https://www.devze.com 2023-04-09 09:11 出处:网络
I\'m playing around with mechanize on a website that appears differently based on your ip. Is there a way to change you ip in mechanize?

I'm playing around with mechanize on a website that appears differently based on your ip.

Is there a way to change you ip in mechanize?

I've tried:

br.set_proxie开发者_运维百科s({"http": '127.0.0.1:80'})

but that timesout. Is there something else I'm supposed to do to make this work?


no, I do not believe this is possible. IP address is set on outgoing packets by your network stack, outside of mechanize's control.


You can use tor with menchanize it will allowed you tu use different IP and anonymous.

import socks
import socket


def create_connection(address, timeout=None, source_address=None):
    sock = socks.socksocket()
    sock.connect(address)
    return sock

And This code before create the browser of mechanize

socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 9050)

socket.socket = socks.socksocket
socket.create_connection = create_connection
0

精彩评论

暂无评论...
验证码 换一张
取 消