【python学习.第五周任务】
来源:互联网 发布:淘宝 各地博物馆 编辑:程序博客网 时间:2024/05/17 10:56
做了上述的准备,简单结合下就可以综合起来做这周的任务了。
一开始我传进GITHUB的代码有不足,一是只有所有网址都检查完才能传进去,这样根本无法测试(电脑跑得慢哈哈),我又改了一下,可以一边扫描一边传进去。为了测试方便,我把遍历换成了两个网址,一个被注册了,一个没被注册,我想效果是一样的。
然后这是改后的代码。。。。。。。
__author__ = 'Administrator'# -*- coding: UTF-8 -*-import urllibimport urllib2import reimport MySQLdbrange=['a','b','c','d','e','f','g','h','i','j','k','l','m','o','p','q','r','s','t','u','v','w','x','y','z']temps = ['aabav','aaaaa']result=[]try: conn=MySQLdb.connect(host='localhost',user='cjw',passwd='123456',port=3306) cur=conn.cursor() conn.select_db('python1') cur.execute('create table url10(URL varchar(20))') url = 'http://www.zgsj.com/domain_reg/domaintrans.asp' for temp in temps: values = {'d_name':"%s.com" %temp, 'dtype':"common", 'drand':"1416053904465"} data = urllib.urlencode(values) user_agent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36' headers = {'User-Agent' : user_agent } req = urllib2.Request(url,data,headers) response = urllib2.urlopen(req) the_page = response.read() reg = r"value='([a-zA-Z]+\.com)' checked" if re.findall(reg,the_page): result.append(re.findall(reg,the_page)) value=re.findall(reg,the_page) cur.execute('insert into url10 values(%s)',value) conn.commit() print str(re.findall(reg,the_page)) else: pass conn.commit() cur.close() conn.close()except MySQLdb.Error,e: print "Mysql Error %d: %s" % (e.args[0], e.args[1])
然后这是结果,,,,,
PS:我觉得,是不是该做完后把表删掉呢,因为这样我测试下就要改一下表的名字,看我都到url9了,就知道我已经测试了9次。
0 0
- 【python学习.第五周任务】
- 第五周 任务一
- 第五周任务一
- 第五周 任务四
- 第五周 任务二
- 第五周 任务三
- 第五周任务一
- 第五周 任务四
- 第五周任务一
- 第五周 任务三
- 第五周任务二
- 第五周 任务一
- 第五周任务三
- 第五周任务二
- 第五周任务三
- 第五周任务四
- 第五周任务3
- 第五周任务四
- COCOS2DX引擎深入三———渲染结构(3.0)
- response细节
- [蓝桥杯][Java] 有趣儿的平方数
- 设计模式之结构型模式
- 使用log4j把日志记录到不同文件
- 【python学习.第五周任务】
- 【toj1312】The Game
- 第十四周OJ
- 字符串-05. 字符串循环左移(20)(部分对)
- 周伯通招聘发现频道之追梦网
- Problem 013——UVa 10474 - Where is the Marble?
- 用Python开始机器学习(10:聚类算法之K均值)
- 两个数组相加
- 第14周项目2-带姓名的成绩单(2)