-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1faa2c8
commit addaec4
Showing
13 changed files
with
274 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<IP>(\d{1,3}\.){3}\d{1,3})', html) | ||
telecom_match = re.search(ur'来自:\s*(?P<telecom>[^.]*?)\.', 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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
beautifulsoup4==4.6.0 | ||
bs4==0.0.1 | ||
lxml==4.2.1 | ||
requests==2.18.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<title>报名查询</title> | ||
<link rel="stylesheet" href="css/style.css"> | ||
</head> | ||
<body> | ||
<header> | ||
<h1 class="logo" ><img src="img/logo.png" alt=""></h1> | ||
</header> | ||
<section class="content"> | ||
<h1 class="title">报名查询</h1> | ||
<form action="#" method="post"> | ||
<p> | ||
<input placeholder="电话" type="text" name="phone" id="phone" class="input-text" maxlength="11"> | ||
<span id="phone_error" class="error-msg"></span> | ||
</p> | ||
<p><button id="search" class="submit-btn" type="submit">查询</button></p> | ||
</form> | ||
<p class="tip"><a href="#">没查到报名?点击这里前往报名→</a></p> | ||
</section> | ||
<footer> | ||
<p>Copyright © 2018 <br/> All Rights Reserved Powered By ISA.</p> | ||
</footer> | ||
<script src="js/do.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
# 第二期项目 | ||
|
||
[后端] 4/11 保存猜数字成绩 | ||
## [后端] 4/11 保存猜数字成绩 | ||
|
||
修改上一个程序,添加如下功能: | ||
1. 当用户猜到数字之后,提示其输入一个昵称作为游戏名称,然后保存成绩,包含昵称,开始时间,耗时,所猜数字,猜测次数; | ||
2. 游戏开启时,若用户已有设置了昵称,则输出提示语:你好!昵称~; | ||
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位时,提示无效的手机号,同时禁用按钮,当输入符合要求时,则按钮恢复可用。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 为没有录取。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# 创软俱乐部项目训练 | ||
|
||
[第一期项目](./01) | ||
[第二期项目](./02) | ||
[第一期项目](./01) | ||
[第二期项目](./02) | ||
[第三期项目](./03) |