alaska's Issues
requests 自定义请求源ip地址
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.poolmanager import PoolManager
import requests
import gevent
class CustomSourceAddrAdpater(HTTPAdapter):
def __init__(self, *args, **kwargs):
source_address = kwargs.pop('source_address')
assert isinstance(source_address, tuple) and len(source_address) == 2
self.source_address = source_address
super(CustomSourceAddrAdpater, self).__init__(*args, **kwargs)
def init_poolmanager(self, connections, maxsize, block=False):
self.poolmanager = PoolManager(num_pools=connections,
maxsize=maxsize,
block=block,
source_address=self.source_address)
s = requests.Session()
a = CustomSourceAddrAdpater(source_address=(random.choice(ips), 0))
s.mount('http://', a)
resp = s.get(url)
原理就是socket连接时bind ip。urllib2也可以实现,但无法使用keep-alive属性。requests 可使用长连接的。
以下urllib2实现
class BindableHTTPConnection(httplib.HTTPConnection):
def connect(self):
"""Connect to the host and port specified in __init__."""
self.sock = socket.socket()
self.sock.bind((self.source_ip, 0))
if isinstance(self.timeout, float):
self.sock.settimeout(self.timeout)
self.sock.connect((self.host, self.port))
def BindableHTTPConnectionFactory(source_ip):
def _get(host, port=None, strict=None, timeout=0):
bhc = BindableHTTPConnection(host, port=port, strict=strict, timeout=timeout)
bhc.source_ip = source_ip
return bhc
return _get
class BindableHTTPHandler(urllib2.HTTPHandler):
def http_open(self, req):
return self.do_open(BindableHTTPConnectionFactory(random.choice(ips)), req)
Html & Dom
const input = document.createElement('input');
document.body.appendChild(input);
input.setAttribute('value', 'test');
input.setAttribute('hidden', true);
document.execCommand('copy')
用js复制时,执行了input.setAttribute('hidden', true);
会无法复制,且不报错。
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.