diff --git a/01/readme.md b/01/readme.md index 6590fde..b9f35db 100644 --- a/01/readme.md +++ b/01/readme.md @@ -1,14 +1,14 @@ # 第一期项目 -[[后端] 3/21 猜数字](./backend) +## [[后端] 3/21 猜数字](./backend) 猜数字是一个古老的游戏,由一个出题者随机出一个数字,由猜题者猜,若所猜数字大于所出数字,则出题者回答『大了』;若小于,则回答『小了』;直到猜题者猜中。现在请编写程序模拟出题者,随机数字在1~1000之间。当使用者猜中时,同时打印出猜测次数。 -[[爬虫] 3/21 获取IP](./crawler) +## [[爬虫] 3/21 获取IP](./crawler) 访问网站:ip.sxisa.com 可以得到本机的外网IP。现在,请编写程序,打印出本机的外网IP。 -[[前端] 3/21 网站设计](./frontend) +## [[前端] 3/21 网站设计](./frontend) 按照设计图制作出对应的网页: diff --git a/02/crawler/Python/main_bs4.py b/02/crawler/Python/main_bs4.py new file mode 100644 index 0000000..500a8ed --- /dev/null +++ b/02/crawler/Python/main_bs4.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import requests +from bs4 import BeautifulSoup + +def get_html(url, encoding='utf-8'): + rsp = requests.get(url) + return rsp.content.decode(encoding) + +def analyze(html): + return BeautifulSoup(html, 'lxml') + +def main(): + html = get_html('http://www.myip.cn/') + document = analyze(html) + fonts = document.find_all('font') + my_ip = 'not found' + telecom = 'not found' + for font in fonts: + innerText = font.get_text().strip() + if innerText.find(u'您的IP') >= 0: + my_ip = innerText[innerText.find(':') + 1:].strip() + elif innerText.find(u'来自') >= 0: + telecom = innerText[innerText.find(':') + 1:innerText.find('.')].strip() + + print(u'IP: {ip} \n运营商: {telecom}'.format(ip=my_ip, telecom=telecom)) + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/02/crawler/Python/main_re.py b/02/crawler/Python/main_re.py new file mode 100644 index 0000000..b3ebc06 --- /dev/null +++ b/02/crawler/Python/main_re.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import requests +import re + +def get_html(url, encoding='utf-8'): + rsp = requests.get(url) + return rsp.content.decode(encoding) + +def main(): + html = get_html('http://www.myip.cn/') + ip_match = re.search(ur'您的IP地址:\s*(?P(\d{1,3}\.){3}\d{1,3})', html) + telecom_match = re.search(ur'来自:\s*(?P[^.]*?)\.', html) + + if ip_match: + my_ip = ip_match.group('IP') + else: + my_ip = 'not found' + + if telecom_match: + telecom = telecom_match.group('telecom') + else: + telecom = 'not found' + + print(u'IP: {ip} \n运营商: {telecom}'.format(ip=my_ip, telecom=telecom)) + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/02/crawler/Python/requirements.txt b/02/crawler/Python/requirements.txt new file mode 100644 index 0000000..63e9915 --- /dev/null +++ b/02/crawler/Python/requirements.txt @@ -0,0 +1,4 @@ +beautifulsoup4==4.6.0 +bs4==0.0.1 +lxml==4.2.1 +requests==2.18.4 \ No newline at end of file diff --git a/02/crawler/node/app.js b/02/crawler/node/app.js new file mode 100644 index 0000000..221067d --- /dev/null +++ b/02/crawler/node/app.js @@ -0,0 +1,36 @@ +#!/usr/bin/env node +const request = require('request'); +const { JSDOM } = require('jsdom'); + +function ip(callback) { + request('http://www.myip.cn/', (err, rsp, body) => { + if (err) throw (err) + const window = new JSDOM(rsp.body).window; + const document = window.document; + // 获取所有的 font 标签 + let fonts = document.getElementsByTagName('font'); + // 过滤出包含IP的标签 + let ipElem = Array.from(fonts).filter(f => f.textContent.indexOf('您的IP') >= 0)[0] || { textContent: '' }; + // 过滤出包含电信运营商的标签 + let telecomElem = Array.from(fonts).filter(f => f.textContent.indexOf('来自') >= 0)[0] || { textContent: '' }; + + // 取出标签文本 + let ip = ipElem.textContent.trim(); + let telecom = telecomElem.textContent.trim(); + + // 根据文本特征提取关键内容 + ip = ip.slice(ip.indexOf(':') + 1).trim(); + telecom = telecom.slice(telecom.indexOf(':') + 1, telecom.indexOf('.')).trim(); + + if (callback) callback({ + ip: ip, + telecom: telecom + }) + }) +} + +module.exports = ip; + +if (require.main === module) { + ip(info => console.log('IP:', info.ip, '运营商:', info.telecom)); +} \ No newline at end of file diff --git a/02/crawler/node/package.json b/02/crawler/node/package.json new file mode 100644 index 0000000..f08c429 --- /dev/null +++ b/02/crawler/node/package.json @@ -0,0 +1,15 @@ +{ + "name": "crawler", + "version": "1.0.0", + "description": "", + "main": "app.js", + "scripts": { + "start": "node ./app.js" + }, + "author": "", + "license": "ISC", + "dependencies": { + "jsdom": "^11.7.0", + "request": "^2.85.0" + } +} diff --git a/02/frontend/css/style.css b/02/frontend/css/style.css new file mode 100644 index 0000000..ef448df --- /dev/null +++ b/02/frontend/css/style.css @@ -0,0 +1,93 @@ +html { + min-height: 100%; + position: relative; +} +body { + max-width: 300px; + margin: auto; + font: 300 1em/1.8 PingFang SC,Lantinghei SC,Microsoft Yahei,Hiragino Sans GB,Microsoft Sans Serif,WenQuanYi Micro Hei,sans; + padding: 0 1em; +} + +.logo { + text-align: center; +} + +.logo img{ + width: 100%; + max-width: 300px; /*最大宽度不能大于图片宽度*/ +} + +:focus { + outline: none; +} + +.content .title{ + text-align: center; + font-size: 300%; + font-weight: 100; +} + +.input-text { + border: none; + width: 100%; + text-align: center; + font-size: 1.5em; + border-bottom: 1px dashed #000; + padding: .2em 0; +} + +.submit-btn { + -webkit-appearance: none; /* 取出ios系统按钮默认带有的渐变样式 */ + background-color: #AD190E; + color: #FFF; + border: 0; + width: 100%; + font-size: 1.5em; + padding: .5em; + border-radius: 1.25em; +} + +.submit-btn:hover { + cursor: pointer; +} + +.submit-btn:active { /*实现按下时按钮收缩效果*/ + padding: .45em; + margin: .05em; +} + +.submit-btn[disabled] { + background-color: #727272; +} + +.error-msg { + display: block; + height: 1.5em; + color: #AD190E; + text-align: center; + font-weight: 500; +} + +.tip { + text-align: center; +} + +.tip a { + color: #CCC; + text-decoration: none; +} + +footer { + text-align: center; + color: #CCC; + height: 4em; +} + +footer p { + font-size: 80%; + position: absolute; + bottom: 0; + width: 100%; + left: 0; +} \ No newline at end of file diff --git a/02/frontend/img/logo.png b/02/frontend/img/logo.png new file mode 100644 index 0000000..027bb52 Binary files /dev/null and b/02/frontend/img/logo.png differ diff --git a/02/frontend/index.html b/02/frontend/index.html new file mode 100644 index 0000000..8cc518a --- /dev/null +++ b/02/frontend/index.html @@ -0,0 +1,30 @@ + + + + + + + 报名查询 + + + +
+

+
+
+

报名查询

+
+

+ + +

+

+
+

没查到报名?点击这里前往报名→

+
+
+

Copyright © 2018
All Rights Reserved Powered By ISA.

+
+ + + \ No newline at end of file diff --git a/02/frontend/js/do.js b/02/frontend/js/do.js new file mode 100644 index 0000000..8557647 --- /dev/null +++ b/02/frontend/js/do.js @@ -0,0 +1,20 @@ +function verify_phone() { + var value = document.getElementById('phone').value; + var error = ''; + var error_msg = document.getElementById('phone_error'); + if (value.length != 11 || isNaN(value)) { + error = '请输入有效的手机号'; + } + error_msg.innerHTML = error; + document.getElementById('search').disabled = !!error; + return !error; +} + +document.getElementById('phone').addEventListener('input', function (ev) { + verify_phone(); +}); + +document.getElementById('search').addEventListener('click', function (ev) { + if (!verify_phone()) + ev.stopPropagation(); +}); \ No newline at end of file diff --git a/02/readme.md b/02/readme.md index 4952690..dfd9934 100644 --- a/02/readme.md +++ b/02/readme.md @@ -1,6 +1,6 @@ # 第二期项目 -[后端] 4/11 保存猜数字成绩 +## [后端] 4/11 保存猜数字成绩 修改上一个程序,添加如下功能: 1. 当用户猜到数字之后,提示其输入一个昵称作为游戏名称,然后保存成绩,包含昵称,开始时间,耗时,所猜数字,猜测次数; @@ -8,11 +8,11 @@ 3. 然后提示选择 1. 玩猜数字;2. 查看历史成绩;3. 更改设置昵称; 4. 实现2,3功能。 -[爬虫] 3/29 获取IP与IP相关信息 +## [[爬虫] 3/29 获取IP与IP相关信息](./crawler) 爬取 www.myip.cn 得到本机的外网IP,IP 地域,运营商。 -[前端] 3/29 表单验证 +## [[前端] 3/29 表单验证](./frontend) 修改上一个网页,添加如下功能: 当用户输入的电话号码非数字与长度不等于11位时,提示无效的手机号,同时禁用按钮,当输入符合要求时,则按钮恢复可用。 \ No newline at end of file diff --git a/03/readme.md b/03/readme.md new file mode 100644 index 0000000..9b6da46 --- /dev/null +++ b/03/readme.md @@ -0,0 +1,8 @@ +# 第三期项目 + +## [爬虫] 4/11 获取域名相关信息 +通过 http://tool.chinaz.com/ Whois查询,得到用户输入的域名的注册信息。 + +## [前端] 4/11 Ajax请求 +修改上一个网页,添加如下功能: +当用户点击『查询』时,通过对 API 接口:http://teach.sxisa.com/api/signup/phone/手机号 发起ajax请求,获取报名者的录取情况,按照返回值的 result 信息判断,1 为已录取,0 为没有录取。 \ No newline at end of file diff --git a/readme.md b/readme.md index 0ef0a82..1ff473e 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,5 @@ # 创软俱乐部项目训练 -[第一期项目](./01) -[第二期项目](./02) +[第一期项目](./01) +[第二期项目](./02) +[第三期项目](./03) \ No newline at end of file