# -*- coding: utf-8 -*-
from threading import Thread
import urllib2
class GetPageThread(Thread):
def __init__(self, url):
self.url = url
self.body = None
super(GetPageThread, self).__init__()
def run(self):
try:
#для некоторых ресурсов доступ будет закрыт
#без user-agent(довольно часто)
req = urllib2.Request(self.url, headers={'User-Agent' : 'Mozilla/5.0'})
self.body = urllib2.urlopen(req).read()
except:
self.body = 'Некорректный адрес'
def body_thread(url):
return GetPageThread(url)
def main():
url = 'http://ya.ru'
#создание потоков
threads = [body_thread(url) for i in range(100)]
#запуск потоков
for thread in threads:
thread.start()
#объединение с основным
for thread in threads:
thread.join()
#что хотелось бы с этим сделать
for thread in threads:
print thread.body.splitlines()
if __name__ == '__main__':
main()
navigator.camera.getPicture(onSuccess, onFail, { quality: 50,
destinationType: Camera.DestinationType.DATA_URL
});
function onSuccess(imageData) {
var image = document.getElementById('myImage');
image.src = "data:image/jpeg;base64," + imageData;
}
function onFail(message) {
alert('Failed because: ' + message);
}
import urllib2
prox = urllib2.ProxyHandler({"http":"http://107.170.106.64:8888"})
opener = urllib2.build_opener(prox)
urllib2.install_opener(opener)
html = urllib2.urlopen("http://2ip.ru").read()
with open("site.html","w",encoding="utf-8") as f:
f.write(html)
f.write(requests.get("http://2ip.ru", proxies={"http": "http://107.170.106.64:8888"}).text)
соответсвенно