开发者

Mechanize you different ip

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜