Я использую python с селеном и браузерным прокси-сервером. Когда происходит действие (щелчок, отправка), я хочу изменить URL-адрес http-запроса. Я не понимаю объяснение прокси-сервера браузера:
request_interceptor(js)[source] Executes the java/js code against each response HttpRequest request, HttpMessageContents contents, HttpMessageInfo messageInfo are available objects to interact with. :param str js: the js/java code to execute
server = Server("C:\\browsermob-proxy-2.1.4\\bin\\browsermob-proxy.bat")
server.start()
proxy = server.create_proxy()
request_js = " *** code *** "
proxy.request_interceptor(request_js)
как мне написать код в «request_js», чтобы изменить URL-адрес запроса? Это возможный пример?
How do I translate the code below in python?
proxy.addRequestFilter(new RequestFilter() {
@Override
public HttpResponse filterRequest(HttpRequest request, HttpMessageContents contents, HttpMessageInfo messageInfo) {
if (messageInfo.getOriginalUri().endsWith("/some-endpoint-to-intercept")) {
// retrieve the existing message contents as a String or, for binary contents, as a byte[]
String messageContents = contents.getTextContents();
// do some manipulation of the contents
String newContents = messageContents.replaceAll("original-string", "my-modified-string");
//[...]
// replace the existing content by calling setTextContents() or setBinaryContents()
contents.setTextContents(newContents);
}
// in the request filter, you can return an HttpResponse object to "short-circuit" the request
return null;
}
});