摘要: selenium 是一个Web自动化测试的软件包,可以用于自动测试Web应用,也可以用于当作简单的爬虫制作工具,这是一个简单的demo,用于爬取Google APP Store中的一个类别:# -*- coding: utf-8 -*-from selenium import webdriverfr... 阅读全文
posted @ 2014-04-16 20:22 jaw-crusher 阅读(1020) 评论(0) 推荐(0)
摘要: phantomjs是一个具有webkit内核的无界面浏览器,有很多强大的功能,做爬虫也是很简单的(当然是简单的爬虫),这是一个爬取搜狗相关搜索的例子,可以多加点东西,或者改成爬取其他网页的爬虫:var page = require('webpage').create();var system = require('system');if (system.args.length != 2) { console.log("input keyword to search!");} else { // 设置编码一般使用System不会出错 utf8反 阅读全文
posted @ 2014-04-04 16:32 jaw-crusher 阅读(466) 评论(0) 推荐(0)
摘要: 获取一个字符串所有连续子串组成集合(set)的长度,居然是Facebook的interview题目,我也做出来了,哈哈:def get_all_substrings(string): length = len(string) alist = [] for i in xrange(length): for j in xrange(i,length): alist.append(string[i:j + 1]) return alistprint get_all_substring('abcde')不过感觉写的有点simple,问问stackoverflow:还是这样写比... 阅读全文
posted @ 2014-03-18 14:35 jaw-crusher 阅读(2327) 评论(0) 推荐(0)
摘要: 问题症状和这里的类似,直接在SQL语句用%拼接string会出现OperationalError: (1054, "Unknown column 'XX' in 'where clause'")错误,使用2.6+版本的Python最好使用format方法,如下:SQL语句:run_sql.sql:create database name;create table just_id_and_name ( id integer primary key auto_increment, name varchar(200) not null);use n 阅读全文
posted @ 2014-03-11 17:52 jaw-crusher 阅读(4272) 评论(0) 推荐(1)
摘要: 计算机网络中的AS号: 首先需要知道什么是自治系统(Autonomous System)自治系统是指使用统一内部路由协议的一组网络。如果成员单位的网络路由器准备采用EGP(Exterior Gateway Protocol) BGP(Border Gateway Protocol)或 IDRP(OSI Inter-Domain Routing Protocol)协议,可以申请AS号码。 一般如果该单位的网络规模比较大或者将来会发展成较大规模的网络,而且有多个出口,建议建立成一个自治系统,这样就需要AS号码。 如果网络规模较小,或者规模较为固定,而且只有一个出口, 可采用静态路由或其它路由协议, 阅读全文
posted @ 2014-03-07 17:02 jaw-crusher 阅读(8220) 评论(0) 推荐(0)
摘要: 1.binary-count找出一个数字的二进制中1的个数:checkio = lambda a: bin(a).count('1')2.absolute-sorting 用绝对值进行排序:def checkio(num_list): num_list = list(num_list) num_list.sort(cmp = lambda a,b:cmp(abs(a), abs(b))) return num_list3.number-radix任意进制转换,异常时候返回-1:def checkio(s_num, base): try: return in... 阅读全文
posted @ 2014-02-23 21:56 jaw-crusher 阅读(477) 评论(0) 推荐(0)
摘要: iframe页面和原本的页面传值方法实例,可以用于获取父页面和子页面的dom对象的值。parent.html: Home Page For Iframe This is for iframe To Get it. iframe.html: Iframe Home Page close iframe Add Element To Parent Page Get Parent Page Ele 在本地的Chrome浏览器无法使用,会出现安全错误。放在服务器上就行了。 阅读全文
posted @ 2014-02-18 11:51 jaw-crusher 阅读(1548) 评论(0) 推荐(0)
摘要: 还在用alert简单粗暴的调试js,试试Chrome的console工具吧。打开Chrome按下F12,进入Console选项卡,进入console模式。1.使用断言调试工具console.assert()如:var num = 100;console.assert(num == 100);断言失败会报错。2.调试过多的信息,需要清除屏幕,使用console.clear()3.console.count()记录函数调用次数,对于调试递归函数很有用。如:var func = function (n) { console.count("func call"); if (n == 阅读全文
posted @ 2014-02-14 11:04 jaw-crusher 阅读(865) 评论(0) 推荐(0)
摘要: 使用两个属性offsetWidth和offsetHeight就可以了。实例如下: Document hello world 可以看出宽度为实际看到的宽度,包括了padding和border的宽度。 阅读全文
posted @ 2014-02-13 15:12 jaw-crusher 阅读(8955) 评论(0) 推荐(0)
摘要: with语句一般用于文件打开,避免使用如下繁琐的格式:fd = Nonetry: fd = open("./hello.txt") for line in fd: print lineexcept Exception as e: print efinally: fd.close()使用with语句如下:with open("./hello.txt") as f: for line in f: print line其他更cool的用法,留到以后慢慢收集。 阅读全文
posted @ 2014-01-14 16:36 jaw-crusher 阅读(136) 评论(0) 推荐(0)