Tag:url

Tag (url)'s result:

Java URL class

在java.net包中定义了URL类,该类用来处理有关URL的内容。 openStream()方法只能读取网络资源,若要既能读取又能发送数据,则要用到URL类的openConnection()方法来创建一个 URLConnection类的对象,此对象在本地机和URL指定的远程节点建立一条HTTP协议的数据通道,可进行双向数据传输 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; public class Urltest { public static void main(String[] args) throws IOException { URL baidu = new URL(“http://www.baidu.com”); System.out.println(“protocol: “+baidu.getProtocol()); System.out.println(“authority: “+baidu.getAuthority()); System.out.println(“host: “+baidu.getHost()); System.out.println(“port: “+baidu.getPort()); System.out.println(“path: “+baidu.getPath()); System.out.println(“query: “+baidu.getQuery()); System.out.println(“filename: “+baidu.getFile()); System.out.println(“ref: “+baidu.getRef()); /*URLConnection baiduconn = baidu.openConnection(); in = new BufferedReader(new InputStreamReader(baiduconn.getInputStream())); */ /*BufferedReader in = new BufferedReader(new InputStreamReader(baidu.openStream())); String inputline; while((inputline = in.readLine())!=null) System.out.println(inputline);*/ /*in.close();*/ } } 参考链接: http://www.runoob.com/java/java-url-processing.html http://blog.csdn.net/witsmakemen/article/details/6989010  

Use python to test url(check_url_speed v1.0)

Environment: win7+python2.7 This program can test url,if the url can open,output normal and use ping to test average speed,else output failed.Then if the url can open but can not ping,I give the url a big number(10000) and output ‘Can not ping  but can open ‘.Finally,I count total urls,normal urls and their ping average speed,also output those urls whick can not ping but can open. #coding:gb2312 #description:check urls and test ping average speed #author:LSA #Date:20170218 import urllib2,time import subprocess import re import optparse #from threading import Thread global count0,count1,count2 count0 = 0 count1 = 0 count2 = 0 global urlave urlave = {} global aves aves = [] global speurls speurls = [] notping = ‘Can not ping but can open!’ def ping_ave_speed(tempUrl): global speurls pingtempUrl = tempUrl.split(‘/’)[2] p = subprocess.Popen([“ping.exe”,pingtempUrl], stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell = True) out = p.stdout.read() reg = re.compile(“平均 = (\d+)ms”, re.IGNORECASE) if not reg.findall(out): speurls.append(tempUrl) return str(10000) else: return str(reg.findall(out)[0]) def test_url(fname): global count0 global count1 global count2 global aves……