Commit d252cc0f authored by 楼超奇's avatar 楼超奇

demo done

parents
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 2.7.12 (/usr/local/bin/python)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
</module>
\ No newline at end of file
<component name="ProjectDictionaryState">
<dictionary name="louchaoqi" />
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
<OptionsSetting value="true" id="Add" />
<OptionsSetting value="true" id="Remove" />
<OptionsSetting value="true" id="Checkout" />
<OptionsSetting value="true" id="Update" />
<OptionsSetting value="true" id="Status" />
<OptionsSetting value="true" id="Edit" />
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 2.7.12 (/usr/local/bin/python)" project-jdk-type="Python SDK" />
<component name="masterDetails">
<states>
<state key="ScopeChooserConfigurable.UI">
<settings>
<splitter-proportions>
<option name="proportions">
<list>
<option value="0.2" />
</list>
</option>
</splitter-proportions>
</settings>
</state>
</states>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/../zige_demo/.idea/demo.iml" filepath="$PROJECT_DIR$/../zige_demo/.idea/demo.iml" />
</modules>
</component>
</project>
\ No newline at end of file
This diff is collapsed.
#!coding=utf-8
from io import open as iopen
from flask import Flask
from flask import send_file
from flask import render_template
from flask import request
from flask import url_for
from flask import redirect
import requests
from pyquery import PyQuery
app = Flask(__name__)
COOIKE = None
FORM_DATA = None
CODE_FILE_NAME = 'code.gif'
def requests_image(url, headers, params=None):
if params:
i = requests.get(url, headers=headers, parmas=params)
else:
i = requests.get(url, headers=headers)
if i.status_code == requests.codes.ok:
with iopen(CODE_FILE_NAME, 'wb') as f:
f.write(i.content)
def data_from_remote():
global COOIKE
global FORM_DATA
site = 'http://zgcx.nhfpc.gov.cn/doctorsearch.aspx'
r = requests.get(site)
cookie = r.headers['Set-Cookie'].split(';')[0]
COOIKE = cookie
data = r.content
pq = PyQuery(data)
FORM_DATA = {
'__VIEWSTATE': pq.find('#__VIEWSTATE').attr('value'),
'__VIEWSTATEGENERATOR': pq.find('#__VIEWSTATEGENERATOR').attr('value'),
'__EVENTVALIDATION': pq.find('#__EVENTVALIDATION').attr('value'),
'ctl00$ContentPlaceHolder1$ButtonSearch': u'查询',
}
headers = {
'Cookie': cookie,
}
requests_image('http://zgcx.nhfpc.gov.cn/pn.aspx', headers=headers)
@app.route('/zige')
def zige():
data_from_remote()
return render_template('yishizige.html')
@app.route('/info')
def info():
return render_template('result.html')
@app.route('/info', methods=['POST'])
def post_info():
global COOIKE
global FORM_DATA
for k in request.form.keys():
FORM_DATA[k] = request.form[k]
headers = {
'Cookie': COOIKE,
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36',
'Origin': 'http://zgcx.nhfpc.gov.cn',
'Referer': 'http://zgcx.nhfpc.gov.cn/doctorsearch.aspx',
'Content-Type': 'application/x-www-form-urlencoded',
'Host': 'zgcx.nhfpc.gov.cn',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Accept-Encoding': 'gzip, deflate',
}
url = 'http://zgcx.nhfpc.gov.cn/doctorsearch.aspx'
d = requests.post(url, headers=headers, data=FORM_DATA)
file_name = 'templates/result.html'
with iopen(file_name, 'wb') as f:
f.write(d.content)
return redirect(url_for('info'))
@app.route('/code.gif')
def code():
return send_file(CODE_FILE_NAME, mimetype='image/gif')
if __name__ == '__main__':
config = dict(
debug=True,
host='127.0.0.1',
port=3000,
)
app.run(**config)
File added
code.gif

1.99 KB

This diff is collapsed.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Examples</title>
<meta name="description" content="">
<meta name="keywords" content="">
<link href="" rel="stylesheet">
</head>
<body>
<form method="post" action="/info">
省份:
<select name="ctl00$ContentPlaceHolder1$ddlProvince" id="ctl00_ContentPlaceHolder1_ddlProvince" class="mySelect">
<option value="11">北京市</option>
<option value="12">天津市</option>
<option value="13">河北省</option>
<option value="14">山西省</option>
<option value="15">内蒙古自治区</option>
<option value="21">辽宁省</option>
<option value="22">吉林省</option>
<option value="23">黑龙江省</option>
<option value="31">上海市</option>
<option value="32">江苏省</option>
<option value="33">浙江省</option>
<option value="34">安徽省</option>
<option value="35">福建省</option>
<option value="36">江西省</option>
<option value="37">山东省</option>
<option value="41">河南省</option>
<option value="42">湖北省</option>
<option value="43">湖南省</option>
<option value="44">广东省</option>
<option value="45">广西壮族自治区</option>
<option value="46">海南省</option>
<option value="50">重庆市</option>
<option value="51">四川省</option>
<option value="52">贵州省</option>
<option value="53">云南省</option>
<option value="54">西藏自治区</option>
<option value="61">陕西省</option>
<option value="62">甘肃省</option>
<option value="63">青海省</option>
<option value="64">宁夏回族自治区</option>
<option value="65">新疆维吾尔自治区</option>
</select>
医师姓名:<input name="ctl00$ContentPlaceHolder1$txtName" type="text" id="ctl00_ContentPlaceHolder1_txtName" class="myTxt" />
所在医疗机构:<input name="ctl00$ContentPlaceHolder1$txtZyUnit" type="text" id="ctl00_ContentPlaceHolder1_txtZyUnit" class="myTxt" />
验证码:<input name="ctl00$ContentPlaceHolder1$checkcode" type="text" id="ctl00_ContentPlaceHolder1_checkcode" class="myTxt" style="width: 80px" />
<img id="imgVilidate" alt="更换验证码" src="code.gif" style="cursor: pointer; vertical-align: bottom"
border="0" onclick="ChangeCheckCode();" height="30" width="100px" />
<a href="#" onclick="ChangeCheckCode();">换一张</a>
<input type="submit" value="提交">
</form>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment