Commit 0caad00b by bonnieyan

提交

parent 9501976d
......@@ -45,4 +45,11 @@ from
from Employee a
left join Department b
on a.DepartmentId = b.Id)c
where c.Department='Sales' order by c.Salary desc limit 3);
\ No newline at end of file
where c.Department='Sales' order by c.Salary desc limit 3);
方法2:
select b.Name as Department,a.Name as Employee, a.Salary
from Employee a , Department b
where a.DepartmentId = b.Id and
(select count(distinct Salary ) from Employee where DepartmentId = b.Id and Salary > a.Salary)< 3
order by Department
\ No newline at end of file
[{"domain": ".jd.com", "expiry": 1552122011, "httpOnly": false, "name": "__jdb", "path": "/", "secure": false, "value": "122270672.4.155212020430628438731|1.1552120204"}, {"domain": ".jd.com", "expiry": 1554712211.109915, "httpOnly": false, "name": "_tp", "path": "/", "secure": false, "value": "n8sVxrwx057lCB%2BTs%2BX%2FOQ%3D%3D"}, {"domain": ".jd.com", "expiry": 1554712211.109885, "httpOnly": false, "name": "pin", "path": "/", "secure": false, "value": "56224314-647339"}, {"domain": ".jd.com", "httpOnly": true, "name": "thor", "path": "/", "secure": false, "value": "1F1F9A0F08020606127F40D59372509E55D5A317C41D74438F3DC33563362641F77467346E3F7D5432E0C924AD6592B55A5452609322F57CEE6E7E6C5D1CC582303FED204D7298AB9AE28781C0304C352CBA259AE3FCE44F9295E5B52F3447AA0B1A33BA5C34DE87373D07341B7E10EFAD2F8075F6A8CBFCC22FC48B9C8BEADF7357A34EA16C6159E4E4005D78330C8BCD18B3C1B1AC6246AB27D377A7E6866C"}, {"domain": ".jd.com", "expiry": 1552984205.217852, "httpOnly": false, "name": "PCSYCityID", "path": "/", "secure": false, "value": "1930"}, {"domain": ".jd.com", "expiry": 1583656211.109874, "httpOnly": false, "name": "pinId", "path": "/", "secure": false, "value": "uPzSSO_V962s8XTbsiv8iQ"}, {"domain": ".jd.com", "expiry": 1552984204, "httpOnly": false, "name": "ipLoc-djd", "path": "/", "secure": false, "value": "22-1930-49324"}, {"domain": ".jd.com", "expiry": 1552984204, "httpOnly": false, "name": "areaId", "path": "/", "secure": false, "value": "22"}, {"domain": ".jd.com", "expiry": 1552122011, "httpOnly": false, "name": "shshshsID", "path": "/", "secure": false, "value": "b247f010593f5a81bf1ad1893fe71c08_2_1552120211999"}, {"domain": "www.jd.com", "expiry": 1583656211, "httpOnly": false, "name": "o2Control", "path": "/", "secure": false, "value": "webp"}, {"domain": ".jd.com", "expiry": 2416120211, "httpOnly": false, "name": "shshshfp", "path": "/", "secure": false, "value": "39ac701fb682f91a5720c9609542a912"}, {"domain": ".jd.com", "expiry": 2416120212, "httpOnly": false, "name": "shshshfpb", "path": "/", "secure": false, "value": "gTZhRNnib1xxP1%2FDRYmqL4w%3D%3D"}, {"domain": ".jd.com", "httpOnly": false, "name": "__jdc", "path": "/", "secure": false, "value": "122270672"}, {"domain": ".jd.com", "httpOnly": false, "name": "ceshi3.com", "path": "/", "secure": false, "value": "201"}, {"domain": ".jd.com", "expiry": 2416120205, "httpOnly": false, "name": "shshshfpa", "path": "/", "secure": false, "value": "7afd0441-93ba-b452-41fc-5b3045f4e4bb-1552120205"}, {"domain": ".jd.com", "expiry": 1553416204, "httpOnly": false, "name": "__jdv", "path": "/", "secure": false, "value": "122270672|direct|-|none|-|1552120204306"}, {"domain": ".jd.com", "expiry": 1554712211.109935, "httpOnly": true, "name": "_pst", "path": "/", "secure": false, "value": "56224314-647339"}, {"domain": ".jd.com", "expiry": 1554712211.109897, "httpOnly": true, "name": "unick", "path": "/", "secure": false, "value": "56224314-647339"}, {"domain": ".jd.com", "expiry": 1709800211.109827, "httpOnly": false, "name": "TrackID", "path": "/", "secure": false, "value": "1pc9JHLqMU-U5WI6P4v9ARwXbV2uIK0xf9S9xul6qWqnafnzjLRR6N9OyKBV37wmsAJhnuzxOPpbmrq6RLxSFJP8e1sV3LE2rh5IGkPxavkI9dd6RWX4W8oiJ9l5zpkVu"}, {"domain": ".jd.com", "expiry": 1567672217.135357, "httpOnly": false, "name": "__jdu", "path": "/", "secure": false, "value": "155212020430628438731"}, {"domain": ".jd.com", "expiry": 1567672211, "httpOnly": false, "name": "__jda", "path": "/", "secure": false, "value": "122270672.155212020430628438731.1552120204.1552120204.1552120204.1"}]
\ No newline at end of file
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
# 这个路径要写你自己的chromedriver所在路径
path = "/home/yanjun/Downloads/chromedriver"
driver = webdriver.Chrome(path)
time.sleep(1)
driver.get("http://www.python.org")
time.sleep(1)
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
time.sleep(1)
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
import time
import os
import json
driver = webdriver.Chrome("/home/yanjun/Downloads/chromedriver")
driver.maximize_window()
def login():
driver.get("https://www.jd.com/")
driver.find_element_by_class_name("link-login").click()
driver.find_element_by_link_text("账户登录").click()
driver.find_element_by_id("loginname").send_keys("17380409735")
driver.find_element_by_id("nloginpwd").send_keys("988105yskyj+_")
driver.find_element_by_id("loginsubmit").click()
save_cookies(driver)
def save_cookies(driver):
# 获取本地路径
file_path = os.getcwd()+ "/cookies/"
if not os.path.exists(file_path):
os.mkdir(file_path)
# 保存cookies到文件中
cookies = driver.get_cookies()
with open(file_path + "jd.cookies", "w") as c:
# 这里必须用dump方式写入文件
# 不然你loads的时候会有问题,
# 格式会不匹配
json.dump(cookies, c)
print(cookies)
def check_cookies():
# 初始化login_status
login_status = False
# 将本地cookies装载到driver中
driver = load_local_cookies_to_driver()
# 校验cookies是否过期,未过期则能访问到订单中心
driver.get("https://order.jd.com/center/list.action")
current_url = driver.current_url
if current_url == "https://order.jd.com/center/list.action":
login_status = True
print("cookies校验通过,登录成功")
return login_status
else:
print("登录失败")
return login_status
def load_local_cookies_to_driver():
file_path = os.getcwd() + "/cookies/"
# 读取cookies信息
jd_cookies_str = open(file_path + "jd.cookies", "r").readline()
# 加载cookies信息
jd_cookies_dict = json.loads(jd_cookies_str)
# 这个地方必须先访问一下网站,然后把旧的cookies 删除掉,再把我们保存的cookies添加进去
driver.get("https://www.jd.com/")
driver.delete_all_cookies()
for cookie in jd_cookies_dict:
driver.add_cookie(cookie)
return driver
def to_thinkpad(driver):
driver.get("https://www.jd.com")
elem = driver.find_element_by_link_text("电脑")
# 鼠标悬停
ActionChains(driver).move_to_element(elem).perform()
time.sleep(3)
driver.find_element_by_link_text("笔记本").click()
# 新开页了,需要切换句柄,否则定位不到
handles = driver.window_handles
index_handle = driver.current_window_handle
for handle in handles:
if handle != index_handle:
driver.switch_to_window(handle)
time.sleep(2)
driver.find_element_by_xpath("//*[@id=\"brand-11518\"]/a").click()
# 7000以上
time.sleep(2)
driver.find_element_by_xpath("//*[@id=\"J_selectorPrice\"]/div/div[2]/div/ul/li[7]/a").click()
# 评论
time.sleep(2)
driver.find_element_by_xpath("//*[@id=\"J_filter\"]/div[1]/div[1]/a[3]").click()
driver.find_element_by_xpath("//*[@id=\"plist\"]/ul/li[1]/div/div[1]/a/img").click()
# 新开页
handles = driver.window_handles
notebook_handle = driver.current_window_handle
for handle in handles:
if handle != index_handle and handle != notebook_handle:
driver.switch_to_window(handle)
time.sleep(2)
# 滑动滚轮
js = "window.scrollTo(0,1500)"
driver.execute_script(js)
time.sleep(2)
# 点击规格与包装
driver.find_element_by_xpath("//*[@id=\"detail\"]/div[1]/ul/li[2]").click()
# 解析标签
result_list = []
# 拿取所有的信息Ptable-item
info_elements = driver.find_elements_by_class_name("Ptable-item")
for info_element in info_elements:
# 获取到每一行的笔记本的配置信息
info_element_dict = get_info_element_dict(info_element)
result_list.append(info_element_dict)
# 保存信息到文件
save_goods_info(result_list)
def get_info_element_dict(info_element):
# 主体等
computer_part = info_element.find_element_by_tag_name("h3")
# 系列等
computer_info_keys = info_element.find_elements_by_tag_name("dt")
# 配置信息等
computer_info_values = info_element.find_elements_by_xpath("dl//dd[not(contains(@class,'Ptable-tips'))]")
# 存储计算机中的key,value
key_and_value_dict = {}
# 用来存储所有的计算机组成信息的字典
parts_dict = {}
for i in range(len(computer_info_keys)):
key_and_value_dict[computer_info_keys[i].text] = computer_info_values[i].text
parts_dict[computer_part.text] = key_and_value_dict
return parts_dict
def save_goods_info(result_list):
file_path = os.getcwd() + "/goods_info/"
if not os.path.exists(file_path):
os.mkdir(file_path)
with open(file_path + "computer.infos", "a", encoding="utf-8") as c:
c.write(str(result_list))
print(str(result_list))
if __name__ == "__main__":
# login()
try:
#用循环控制校验的登录态
loop_status = True
while loop_status:
#校验cookies是否过期
login_status = check_cookies()
if login_status:
loop_status = False
else:
login()
to_thinkpad(driver)
finally:
time.sleep(2)
driver.quit()
[{'主体': {'系列': 'ThinkPad E480', '型号': 'ThinkPad E480(20KNA012CD)', '颜色': '冰原银', '平台': 'Intel', '认证型号': 'ThinkPad E480'}}, {'操作系统': {'操作系统': 'Windows 10 家庭版'}}, {'处理器': {'CPU类型': 'Intel 第8代 酷睿', 'CPU型号': 'i7-8550U', 'CPU速度': '1.8GHz睿频至4.0GHz', '三级缓存': '8M', '核心': '四核'}}, {'内存': {'内存容量': '16GB', '插槽数量': '2 x SO-DIMM'}}, {'硬盘': {'硬盘容量': '1TB', '转速': '5400转/分钟', '固态硬盘': '256GB SSD'}}, {'显卡': {'类型': '独立显卡', '显示芯片': 'AMD Radeon RX550 2GB GDDR5 独立显存', '显存容量': '独立2GB'}}, {'光驱': {'光驱类型': '无光驱'}}, {'显示器': {'屏幕尺寸': '14英寸', '屏幕规格': '14.0英寸', '显示比例': '宽屏16:9', '物理分辨率': '1920×1080', '屏幕类型': 'LED背光'}}, {'通信': {'内置蓝牙': '蓝牙4.1', '局域网': '10/100/1000Mbps', '无线局域网': '有'}}, {'端口': {'USB2.0': '1 个', '音频端口': '耳机、麦克风二合一接口', 'RJ45': '1个', 'USB3.0': '2个'}}, {'音效系统': {'扬声器': '内置扬声器', '内置麦克风': '有'}}, {'输入设备': {'键盘': '背光键盘', '触摸板': '有', '指点杆': '有'}}, {'其它设备': {'网络摄像头': '有', '摄像头像素': '720p', '指纹识别': '无'}}, {'电源': {'电池': '其它', '续航时间': '5-8小时', '电源适配器': '100-240V自适应交流电源适配器'}}, {'机器规格': {'尺寸': '约19.9mm x 329mm x 242mm', '净重': '约1.75kg'}}]
\ No newline at end of file
from selenium import webdriver
import time
def search_12306():
try:
driver = webdriver.Chrome("/workspace/greedy_ai/python_and_ai/chromedriver")
driver.get("https://www.12306.cn/index/")
from_element = driver.find_element_by_id("fromStationText")
time.sleep(2)
from_element.click()
from_element.send_keys("北京")
time.sleep(2)
driver.find_element_by_xpath("//*[text()='北京北']").click()
to_element = driver.find_element_by_id("toStationText")
to_element.click()
to_element.send_keys("长春")
time.sleep(2)
driver.find_element_by_xpath("//*[text()='长春南']").click()
js = "$('input[id=train_date]').removeAttr('readonly')"
driver.execute_script(js)
date_element = driver.find_element_by_id("train_date")
date_element.click()
date_element.clear()
date_element.send_keys("2019-03-10")
driver.find_element_by_class_name("form-label").click()
driver.find_element_by_id("search_one").click()
finally:
time.sleep(3)
driver.quit()
search_12306()
[{"domain": ".jd.com", "expiry": 1551617572, "httpOnly": false, "name": "__jdb", "path": "/", "secure": false, "value": "122270672.4.1551615763598316674308|1.1551615764"}, {"domain": ".jd.com", "expiry": 1554207771.315967, "httpOnly": false, "name": "_tp", "path": "/", "secure": false, "value": "n8sVxrwx057lCB%2BTs%2BX%2FOQ%3D%3D"}, {"domain": ".jd.com", "expiry": 1554207771.315905, "httpOnly": false, "name": "pin", "path": "/", "secure": false, "value": "56224314-647339"}, {"domain": ".jd.com", "expiry": 1583151771.315889, "httpOnly": false, "name": "pinId", "path": "/", "secure": false, "value": "uPzSSO_V962s8XTbsiv8iQ"}, {"domain": ".jd.com", "httpOnly": true, "name": "thor", "path": "/", "secure": false, "value": "D40795D92FB4430806B2315CB2A46569E1A4278B312D3BB8ABB822466E87C6C8A52D815E9AB64E02FBEB730F47B61CDAF9B6403CF07C06A5F26233129BDA919A62B6FA8881D958F789BE8C0648D273ED7F107D63709F2A1168B42B83DCA3C8318A7617F8A59BB9F2307C62719F2D711890FF1D07EBCEB5F507A35BC99A4CADA8DEC70BD5BD640D131EC036E09D0863C07F4811A7FFECF01D27534D322CFC4D50"}, {"domain": ".jd.com", "expiry": 2415615773, "httpOnly": false, "name": "shshshfpb", "path": "/", "secure": false, "value": "vPlaODoLKo5vf9y2A46Kkow%3D%3D"}, {"domain": ".jd.com", "expiry": 2415615773, "httpOnly": false, "name": "shshshfp", "path": "/", "secure": false, "value": "2661be46ec9754594c022f17bf2f09d0"}, {"domain": ".jd.com", "expiry": 1552479764.371741, "httpOnly": false, "name": "PCSYCityID", "path": "/", "secure": false, "value": "1930"}, {"domain": ".jd.com", "expiry": 1554207771.315997, "httpOnly": true, "name": "_pst", "path": "/", "secure": false, "value": "56224314-647339"}, {"domain": ".jd.com", "expiry": 1554207771.315923, "httpOnly": true, "name": "unick", "path": "/", "secure": false, "value": "56224314-647339"}, {"domain": ".jd.com", "expiry": 1709295771.315833, "httpOnly": false, "name": "TrackID", "path": "/", "secure": false, "value": "140c8598s8h_LAz3En9YOM2kFW5GowfpD_SBeTVT39RdbAHiXiEJQOZekM6kFFVhgZMKBTYVEFUjXAsOJ3icey_BnnHR9RzbkshLErZre7A7DVByqMd-XGFNfdtQ3obDC"}, {"domain": ".jd.com", "expiry": 1567167772, "httpOnly": false, "name": "__jda", "path": "/", "secure": false, "value": "122270672.1551615763598316674308.1551615764.1551615764.1551615764.1"}, {"domain": ".jd.com", "expiry": 1567167776.688539, "httpOnly": false, "name": "__jdu", "path": "/", "secure": false, "value": "1551615763598316674308"}, {"domain": ".jd.com", "expiry": 1551617573, "httpOnly": false, "name": "shshshsID", "path": "/", "secure": false, "value": "69d5f853054241ef7a93a84ed52e7fb0_2_1551615773857"}, {"domain": "www.jd.com", "expiry": 1583151772, "httpOnly": false, "name": "o2Control", "path": "/", "secure": false, "value": "webp"}, {"domain": ".jd.com", "httpOnly": false, "name": "__jdc", "path": "/", "secure": false, "value": "122270672"}, {"domain": ".jd.com", "httpOnly": false, "name": "ceshi3.com", "path": "/", "secure": false, "value": "201"}, {"domain": ".jd.com", "expiry": 2415615764, "httpOnly": false, "name": "shshshfpa", "path": "/", "secure": false, "value": "030fbfd2-9547-0662-5dda-b9bac924817b-1551615764"}, {"domain": ".jd.com", "expiry": 1552911763, "httpOnly": false, "name": "__jdv", "path": "/", "secure": false, "value": "122270672|direct|-|none|-|1551615763598"}]
\ No newline at end of file
import pymongo
# 链接mongdb数据库
client = pymongo.MongoClient(host="localhost", port=27017,
username="admin", password="123456"
)
# 链接数据库
db = client.python_ui
# 制定操作的集合(表)
collection = db.my_test_collection
# collection = db['my_test_collection']
# 插入数据
info_dict = {
"id": 1,
"name": "张三",
"age": 20
}
# re = collection.insert(info_dict)
# print(re)
info_dict1 = {
"id": 2,
"name": "张三2",
"age": 20
}
info_dict2 = {
"id": 3,
"name": "张三3",
"age": 20
}
# re = collection.insert_many([info_dict1, info_dict2])
# print(re)
info_dict3 = {
"my_list": [
{
"id": 10,
"name": "小化",
"age": 21
},
{
"id": 11,
"name": "小化1",
"age": 22,
"test": "yyy"
},
],
"comment": "这是我的练习数据"
}
# re = collection.insert_one(info_dict3)
# print(re)
# re = collection.find_one({"id": 2})# 返回的是具体结果
# re = collection.find({"id": 2}) # 返回的是对象
# print(re)
# 返回的是对象
re = collection.find({"id": 2}, {"name"})
# print(re)
# for r in re:
# print(r)
# 同个list算一条数据
# re = collection.find_one({"my_list.id":11})
# print(re)
# 更新操作
'''
1.查询到想要更新的数据
2.更新结果 set
3.执行更新
'''
filter_data = {"my_list": 10}
filter_re = collection.find_one(filter_data)
filter_re["school"] = "MIT"
re = collection.update(filter_data, {"$set": filter_re})
print(re)
\ No newline at end of file
{
"presets": [
["env", { "modules": false }],
"stage-3"
]
}
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
.DS_Store
node_modules/
dist/
npm-debug.log
yarn-error.log
# Editor directories and files
.idea
*.suo
*.ntvs*
*.njsproj
*.sln
# my-vue-2
> A Vue.js project
## Build Setup
``` bash
# install dependencies
npm install
# serve with hot reload at localhost:8080
npm run dev
# build for production with minification
npm run build
```
For detailed explanation on how things work, consult the [docs for vue-loader](http://vuejs.github.io/vue-loader).
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>my-vue-2</title>
</head>
<body>
<div id="app"></div>
<script src="/dist/build.js"></script>
</body>
</html>
This source diff could not be displayed because it is too large. You can view the blob instead.
{
"name": "my-vue-2",
"description": "A Vue.js project",
"version": "1.0.0",
"author": "bonnieyan <525663314@qq.com>",
"license": "MIT",
"private": true,
"scripts": {
"dev": "cross-env NODE_ENV=development webpack-dev-server --open --hot",
"build": "cross-env NODE_ENV=production webpack --progress --hide-modules"
},
"dependencies": {
"vue": "^2.5.11",
"vue-router": "^3.0.2"
},
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 8"
],
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-env": "^1.6.0",
"babel-preset-stage-3": "^6.24.1",
"cross-env": "^5.0.5",
"css-loader": "^0.28.7",
"file-loader": "^1.1.4",
"vue-loader": "^13.0.5",
"vue-template-compiler": "^2.4.4",
"webpack": "^3.6.0",
"webpack-dev-server": "^2.9.1"
}
}
<template>
<div>
<!--事件绑定-->
<input @keydown.enter="onkeydown">
<input @keydown.13="onkeydown13">
<!--自定义事件-->
<component-a @my-event="onComaMyEvent"></component-a>
<!--表单数据的双向绑定-->
<input v-model="myValue" type="text">
{{ myValue }}
<input v-model.lazy="myValueLazy" type="text">
{{myValueLazy}} {{typeof (myValueLazy)}}
<input v-model.number="myValueNumber" type="text">
{{typeof (myValueNumber)}}
<br>
<!--多选框动态数据的绑定-->
<input v-model="myBox" type="checkbox" value="a">
<input v-model="myBox" type="checkbox" value="b">
<input v-model="myBox" type="checkbox" value="c">
{{ myBox }}
<!--单选框-->
<input v-model="myBox1" type="radio" value="1">
<input v-model="myBox1" type="radio" value="2">
<input v-model="myBox1" type="radio" value="3">
{{ myBox1 }}
<!--下拉选择框-->
<select v-model="selection">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
{{selection}}
<select v-model="selectionfor">
<option v-for="item in selectOptions" v-bind:value="item.value">{{item.text}}</option>
</select>
{{ selectionfor }}
<!--计算属性-->
<input type="text" v-model="myvalue1">
{{ myValueWithoutNum }}
<!--属性监听 watch-->
<input type="text" v-model="myVal">
<!--组件的动态渲染-->
<!--<div :is="comToRender"></div>-->
<!--父子组件传递信息-->
<!--<component-b 数字="51" number-two="123123">-->
<component-b>
</component-b>
<!--插槽功能-->
<component-b :my-value="myVal">
<p>123</p>
</component-b>
<component-b :my-value="myVal">
<p>123</p>
<p slot="header">这是头</p>
<p slot="footer">这是脚</p>
</component-b>
<!--在挂在点上,动态的切换组件-->
<button v-on:click="toggleComponent">
切换子组件
</button>
<div class="ab">
<div :is="currentView"></div>
</div>
</div>
</template>
<script>
import componentA from './components/a'
import componentB from './components/b'
import componentHello from './components/HelloWorld'
export default {
components:{
componentA,
componentHello,
componentB
},
data() {
return{
myValue:'',
myValueLazy:'',
myValueNumber:0,
myBox:[],
myBox1:[],
selection:1,
selectionfor:0,
selectOptions:[
{
text:'apple',
value:0
},
{
text:'banana',
value:1
}
],
myvalue1:"",
myVal:'',
comToRender:'component-hello',
currentView:'component-a'
}
},
methods:{
onkeydown(){
console.log("onkeydown")
},
onkeydown13(){
console.log("onkeydown13")
},
onComaMyEvent(paramfromA){
console.log("onComaMyEvent:" + paramfromA)
},
toggleComponent(){
if(this.currentView === 'component-a'){
this.currentView = 'component-b'
}else {
this.currentView = 'component-a'
}
}
},
computed:{
myValueWithoutNum:function () {
return this.myvalue1.replace(/\d/g,'')
}
},
watch:{
myVal: function (val, oldVal) {
console.log(val, oldVal)
}
}
}
</script>
<style>
</style>
<template>
<div class="hello">
<h1>{{ msg }}</h1>
<h2>Essential Links</h2>
<ul>
<li>
<a
href="https://vuejs.org"
target="_blank"
>
Core Docs
</a>
</li>
<li>
<a
href="https://forum.vuejs.org"
target="_blank"
>
Forum
</a>
</li>
<li>
<a
href="https://chat.vuejs.org"
target="_blank"
>
Community Chat
</a>
</li>
<li>
<a
href="https://twitter.com/vuejs"
target="_blank"
>
Twitter
</a>
</li>
<br>
<li>
<a
href="http://vuejs-templates.github.io/webpack/"
target="_blank"
>
Docs for This Template
</a>
</li>
</ul>
<h2>Ecosystem</h2>
<ul>
<li>
<a
href="http://router.vuejs.org/"
target="_blank"
>
vue-router
</a>
</li>
<li>
<a
href="http://vuex.vuejs.org/"
target="_blank"
>
vuex
</a>
</li>
<li>
<a
href="http://vue-loader.vuejs.org/"
target="_blank"
>
vue-loader
</a>
</li>
<li>
<a
href="https://github.com/vuejs/awesome-vue"
target="_blank"
>
awesome-vue
</a>
</li>
</ul>
</div>
</template>
<script>
export default {
name: 'HelloWorld',
data () {
return {
msg: 'Welcome to Your Vue.js App'
}
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1, h2 {
font-weight: normal;
}
ul {
list-style-type: none;
padding: 0;
}
li {
display: inline-block;
margin: 0 10px;
}
a {
color: #42b983;
}
</style>
<template>
<div>
{{msg}}
<button @click="emitMyEvent">A组件中的按钮</button>
</div>
</template>
<script>
export default {
data(){
return{
msg:"我是组件A"
}
},
methods:{
emitMyEvent(){
this.$emit('my-event', this.msg)
}
}
}
</script>
<style scoped>
</style>
<template>
<div>
{{msg}}
{{ 数字 }}
{{ numberTwo }}
{{myValue}}
<slot>插槽没有插上</slot>
<slot name="header"> 没有头 </slot>
<p>中间的内容</p>
<slot name="footer"> 没有脚 </slot>
</div>
</template>
<script>
export default {
props:['数字','number-two','my-value'],
data(){
return{
msg:"我是B组件"
}
}
}
</script>
<style scoped>
</style>
import Vue from 'vue'
import App from './App.vue'
new Vue({
el: '#app',
render: h => h(App)
})
var path = require('path')
var webpack = require('webpack')
module.exports = {
entry: './src/main.js',
output: {
path: path.resolve(__dirname, './dist'),
publicPath: '/dist/',
filename: 'build.js'
},
module: {
rules: [
{
test: /\.css$/,
use: [
'vue-style-loader',
'css-loader'
],
}, {
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
}
// other vue-loader options go here
}
},
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.(png|jpg|gif|svg)$/,
loader: 'file-loader',
options: {
name: '[name].[ext]?[hash]'
}
}
]
},
resolve: {
alias: {
'vue$': 'vue/dist/vue.esm.js'
},
extensions: ['*', '.js', '.vue', '.json']
},
devServer: {
historyApiFallback: true,
noInfo: true,
overlay: true
},
performance: {
hints: false
},
devtool: '#eval-source-map'
}
if (process.env.NODE_ENV === 'production') {
module.exports.devtool = '#source-map'
// http://vue-loader.vuejs.org/en/workflow/production.html
module.exports.plugins = (module.exports.plugins || []).concat([
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
}),
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
compress: {
warnings: false
}
}),
new webpack.LoaderOptionsPlugin({
minimize: true
})
])
}
from selenium import webdriver
driver = webdriver.Chrome("/home/yanjun/Downloads/chromedriver")
driver.get("https://passport.jd.com/new/login.aspx")
'''
1.强制等待 time.sleep
2.隐性等待 driver.implicitly_wait(10) 最长等待10s
'''
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
locator = (By.CSS_SELECTOR, ".login-tab.login-tab-r")
element = WebDriverWait(driver, 10, 1).until(EC.presence_of_element_located(locator))
element.click()
class Person():
def __init__(self):
print("构造方法运行")
# 这个new方法是在Person实例化的时候首先运行,这个方法的返回值决定到时实例化哪个类
def __new__(cls, *args, **kwargs):
print("new方法运行")
return object.__new__(Person)
# return Dog()
# 这个方法可以让类像函数一样被调用
def __call__(self, *args, **kwargs):
print("call方法运行")
def __del__(self):
print("析构方法运行")
class Dog():
def __init__(self):
print("dog __init__方法")
def run(self):
print("dog run")
p = Person()
# p.run()
p(1)
def set_mysql_config(env):
if env == "dev":
db_config = {
'host': 'localhost',
'user': 'root',
'passwd': 'root',
'db': 'test_db',
'port': 3306,
'charset': 'utf8'
}
if env == "pro":
db_config = {
'host': 'localhost',
'user': 'root',
'passwd': 'root',
'db': 'test_db',
'port': 3306,
'charset': 'utf8'
}
return db_config
# 我们来定义Field类,用来保存数据库表的字段名称和字段类型
class Field(object):
def __init__(self, column_name, column_type):
self.column_name = column_name
self.column_type = column_type
class StringField(Field):
def __init__(self, column_name):
super(StringField,self).__init__(column_name, 'varchar(200)')
class IntegerField(Field):
def __init__(self, column_name):
super(IntegerField, self).__init__(column_name, 'bigint')
class TextField(Field):
def __init__(self, column_name):
super(TextField, self).__init__(column_name, 'text')
# 第二种写法
class DataField(Field):
def __init__(self, column_name, column_type):
super(DataField, self).__init__(column_name, column_type)
from object_packaging.field import Field,StringField,IntegerField
from object_packaging.orm import Model
class Goods(Model):
computer_part_name = StringField("computer_part_name")
computer_info = StringField("computer_info")
# goods = Goods()
# goods.insert(["computer_part_name", "computer_info"], ["我的主体", "我的电脑"])
goods = Goods()
r = goods.select(["computer_part_name", "computer_info"],["computer_part_name='我的主体'"])
print(r)
import pymysql
from DBUtils.PooledDB import PooledDB
from object_packaging.config.mysql_config import set_mysql_config
def create_pool():
db_config = set_mysql_config("dev")
return PooledDB(pymysql,
5,
host=db_config['host'],
user=db_config['user'],
passwd=db_config['passwd'],
db=db_config['db'],
port=db_config['port'],
charset=db_config['charset']).connection()
\ No newline at end of file
class Person():
pass
#
# print(Person)
#
# p = Person
# print(p)
# p.name = "张三"
# print(p.name)
# def func(p):
# print(p.name)
#
#
# func(Person)
# type 动态创建类
# print(type(p))
# print(type("2"))
# print(type(1))
def get_class(name):
if name == "dog":
class Dog():
def run(self):
print("dog run")
return Dog
else:
class Cat():
def run(self):
print("cat run")
return Cat
# c = get_class("dog")
# print(c)
# c.run(c)
# c = get_class(c)
# print(c)
# c.run(c)
Person2 = type('Person2', (), {})
# print(Person2)
p2 = Person2()
# print(p2)
class Person3():
name = "张三"
# print(Person3.name)
Person3 = type('Person3', (), {'name': '李四'})
# print(Person3.name)
# 继承
Person4 = type('Person4', (Person3,), {})
print(Person4.name)
def person4_run(self):
print("person4 run")
@staticmethod
def person4_run2():
print("person4 run2")
Person4 = type('Person4', (Person3,), {'person4_run':person4_run,'person4_run2':person4_run2})
p = Person4()
p.person4_run()
p.person4_run2()
# 元类,可生成类,类可生成实例
class MyMetaClass(type):
def __new__(cls, name, bases, attrs):
print("元类new方法运行")
print(name)
print(bases)
attrs['add'] = lambda self, value: value+value
print(attrs)
return type.__new__(cls, name, bases, attrs)
class MyClass(Person4,metaclass=MyMetaClass):
pass
# 用metaclass 实例化 myclass
my_class = MyClass()
r = my_class.add(2)
print(r)
\ No newline at end of file
from object_packaging.field import Field
from object_packaging.my_database import create_pool
# 定义一个元类,控制model对象的创建
class ModelMetaClass(type):
def __new__(cls, table_name, bases, attrs):
if table_name == "Model":
return super(ModelMetaClass, cls).__new__(cls, table_name, bases, attrs)
mappings = dict()
for k, v in attrs.items():
# 保存类属性和列的映射关系到mappings字典中
if isinstance(v, Field):
mappings[k] = v # 这样,这个mappings就存放了 属性名称和字段名称及列的名字
for k in mappings.keys():
attrs.pop(k) # 只有在实例中才可以进行访问。也就是说使用类名.属性就不能访问了
# 把表名转换为小写,表名就是类名
# 这个处理略显粗糙,应该继续做一些健壮性的判断,比如ModelMetaClass 变成表名应该是model_meta_class
attrs['__table__'] = table_name.lower()
# 保存属性和列的映射关系,创建类时添加一个__mappings__类的属性
attrs['__mappings__'] = mappings
return super(ModelMetaClass, cls).__new__(cls, table_name, bases, attrs)
# 编写一个model子类,这个类用于被具体的model对象继承。 它实现了具体的增删改查方法
# 这样以后的每一个model就都有了这些方法
# 这里边我又继承了dict,那么也就是说这个Model也可以使用dict的方法
class Model(dict, metaclass=ModelMetaClass):
def __init__(self, **kwargs):
super(Model, self).__init__(**kwargs)
def __getattr__(self, item):
try:
return self[item]
except KeyError:
raise AttributeError("这个Model没有这个属性,这个属性是%s" % item)
def __setattr__(self, key, value):
self[key] = value
def insert(self, column_list, param_list):
print("调用了insert方法")
fields = []
for k, v in self.__mappings__.items():
fields.append(k)
for key in column_list:
if key not in fields:
raise RuntimeError("field not found")
args = self.__check_params(param_list)
sql = 'insert into %s (%s) values (%s)' % (self.__table__, ','.join(column_list), ','.join(args))
res = self.__do_execute(sql)
print(res)
def __check_params(self, param_list):
args = []
# insert into .... values "va"lue"
for param in param_list:
if "\"" in param:
param = param.replace("\"", "\\\"")
param = "\"" + param + "\""
args.append(param)
return args
def __do_execute(self,sql):
conn = create_pool()
cur = conn.cursor()
print(sql)
if "select" in sql:
cur.execute(sql)
rs = cur.fetchall()
else:
rs = cur.execute(sql)
conn.commit()
cur.close()
return rs
# 下边是作业
# get select
def select(self, column_list, where_list):
print("调用了select方法")
args = []
fields = []
for k,v in self.__mappings__.items():
fields.append(k)
for key in column_list:
if key not in fields:
raise RuntimeError("field not found")
for key in where_list:
args.append(key)
sql = 'select %s from %s where %s' % (','.join(column_list), self.__table__, ' and '.join(args))
res = self.__do_execute(sql)
return res
# update
def update(self, set_column_list, where_list):
print("调用了update方法")
args = []
fields = []
for k,v in self.__mappings__.items():
fields.append(k)
for key in set_column_list:
if key not in fields:
raise RuntimeError("field not found")
for key in where_list:
args.append(key)
sql = 'update %s set %s where %s' % (self.__table__, ','.join(set_column_list), ' and '.join(args))
print(sql)
res = self.__do_execute(sql)
return res
# delete
def delete(self, where_list):
print("调用delete方法")
args = []
for key in where_list:
args.append(key)
sql = 'delete from %s where %s' % (self.__table__, ' and '.join(args))
res = self.__do_execute(sql)
return res
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from threading import Thread
# 用来写我的业务逻辑
def to_baidu(name,server_address):
print(name + "启动")
driver = webdriver.Remote(
command_executor=server_address,
desired_capabilities=DesiredCapabilities.CHROME
)
driver.get("https://www.baidu.com")
# 这个变量用来存储我所有的远程服务地址
data = {
"linux": "http://192.168.0.105:4444/wd/hub",
# "windows": "http://192.168.1.38:4444/wd/hub"
}
threads = []
for name, url in data.items():
t = Thread(target=to_baidu, args=(name, url))
threads.append(t)
for t in threads:
t.start()
[{"domain": ".jd.com", "expiry": 1555314095.070558, "httpOnly": false, "name": "_tp", "path": "/", "secure": false, "value": "n8sVxrwx057lCB%2BTs%2BX%2FOQ%3D%3D"}, {"domain": ".jd.com", "httpOnly": false, "name": "ceshi3.com", "path": "/", "secure": false, "value": "201"}, {"domain": ".jd.com", "expiry": 1555314095.070471, "httpOnly": false, "name": "pin", "path": "/", "secure": false, "value": "56224314-647339"}, {"domain": ".jd.com", "expiry": 1584258095.070423, "httpOnly": false, "name": "pinId", "path": "/", "secure": false, "value": "uPzSSO_V962s8XTbsiv8iQ"}, {"domain": ".jd.com", "httpOnly": true, "name": "thor", "path": "/", "secure": false, "value": "DE6D02F0B1CF7638E1823092F40B20DF6914DF25F4DFF23D7688AE03DAB71402897CDACAADE0B0162E86AF7EC2A8D27F1B3AE0C575F9338BD27F4142A9A618F29891B0CC189F41ADD0EADF4EDFF582C0A342BE21EA43B51D0B04FBC1CA2B861AA70284DD8181A0BDD1964B1A2C9B3ECF9FC9977DA442A1F450DAD4CD893C70D8583D8486E5FA05B5A5F581FA48F70E1AB028C51A8FE40679B569C6ED66441985"}, {"domain": ".jd.com", "expiry": 1552723897, "httpOnly": false, "name": "shshshsID", "path": "/", "secure": false, "value": "29747f3faf26ede012d65d5a36aa9249_7_1552722097145"}, {"domain": "www.jd.com", "expiry": 1584258096, "httpOnly": false, "name": "o2Control", "path": "/", "secure": false, "value": "webp"}, {"domain": ".jd.com", "expiry": 2416721943, "httpOnly": false, "name": "shshshfpa", "path": "/", "secure": true, "value": "5501c22e-4010-734a-5312-b3b6edf83a5b-1552721943"}, {"domain": ".jd.com", "expiry": 1555314095.070645, "httpOnly": true, "name": "_pst", "path": "/", "secure": false, "value": "56224314-647339"}, {"domain": ".jd.com", "expiry": 1555314095.070499, "httpOnly": true, "name": "unick", "path": "/", "secure": false, "value": "56224314-647339"}, {"domain": ".jd.com", "expiry": 1553585942, "httpOnly": false, "name": "areaId", "path": "/", "secure": true, "value": "22"}, {"domain": ".jd.com", "expiry": 1710402095.070327, "httpOnly": false, "name": "TrackID", "path": "/", "secure": false, "value": "17dobD4SNw_Ol4_oh3wgCaoYRA3BU6qgLN6KSH0nDaAsx0PaPcCosvqVg9AHgxW-QLAU38bOFw5qmGrIw993NA5w0q5csiRi95msCr2WPoc6NDQmcEuwaE6Wj-u44iw9H"}, {"domain": ".jd.com", "expiry": 1568274103.042252, "httpOnly": false, "name": "__jdu", "path": "/", "secure": false, "value": "15527219425111555750665"}, {"domain": ".jd.com", "expiry": 1568274096, "httpOnly": false, "name": "__jda", "path": "/", "secure": false, "value": "122270672.15527219425111555750665.1552721943.1552721943.1552721943.1"}, {"domain": ".jd.com", "expiry": 1554017942, "httpOnly": false, "name": "__jdv", "path": "/", "secure": true, "value": "122270672|direct|-|none|-|1552721942513"}, {"domain": ".jd.com", "httpOnly": false, "name": "__jdc", "path": "/", "secure": false, "value": "122270672"}, {"domain": ".jd.com", "expiry": 2416722097, "httpOnly": false, "name": "shshshfp", "path": "/", "secure": false, "value": "2661be46ec9754594c022f17bf2f09d0"}, {"domain": ".jd.com", "expiry": 2416722097, "httpOnly": false, "name": "shshshfpb", "path": "/", "secure": false, "value": "n84L1%2BzNvGuCBYbsqZ6SDIQ%3D%3D"}, {"domain": ".jd.com", "expiry": 1552723896, "httpOnly": false, "name": "__jdb", "path": "/", "secure": false, "value": "122270672.29.15527219425111555750665|1.1552721943"}, {"domain": ".jd.com", "expiry": 1553585942, "httpOnly": false, "name": "ipLoc-djd", "path": "/", "secure": true, "value": "22-1930-49324"}, {"domain": ".jd.com", "expiry": 1553585943.521269, "httpOnly": false, "name": "PCSYCityID", "path": "/", "secure": true, "value": "1930"}]
\ No newline at end of file
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
import time
from save_goods_to_db.jingdong.jd_cookies import *
from save_goods_to_db.jingdong.my_mysql import save_goods_tomysql
def login(driver):
driver.get("https://www.jd.com/")
driver.find_element_by_class_name("link-login").click()
driver.find_element_by_link_text("账户登录").click()
driver.find_element_by_id("loginname").send_keys("17380409735")
driver.find_element_by_id("nloginpwd").send_keys("988105yskyj+_")
driver.find_element_by_id("loginsubmit").click()
save_cookies(driver)
def to_thinkpad(driver):
driver.get("https://www.jd.com")
time.sleep(3)
elem = driver.find_element_by_link_text("电脑")
# 鼠标悬停
ActionChains(driver).move_to_element(elem).perform()
time.sleep(3)
driver.find_element_by_link_text("笔记本").click()
# 新开页了,需要切换句柄,否则定位不到
handles = driver.window_handles
index_handle = driver.current_window_handle
for handle in handles:
if handle != index_handle:
driver.switch_to_window(handle)
time.sleep(2)
driver.find_element_by_xpath("//*[@id=\"brand-11518\"]/a").click()
# 7000以上
time.sleep(2)
driver.find_element_by_xpath("//*[@id=\"J_selectorPrice\"]/div/div[2]/div/ul/li[7]/a").click()
# 评论
time.sleep(2)
driver.find_element_by_xpath("//*[@id=\"J_filter\"]/div[1]/div[1]/a[3]").click()
driver.find_element_by_xpath("//*[@id=\"plist\"]/ul/li[1]/div/div[1]/a/img").click()
# 新开页
handles = driver.window_handles
notebook_handle = driver.current_window_handle
for handle in handles:
if handle != index_handle and handle != notebook_handle:
driver.switch_to_window(handle)
time.sleep(2)
# 滑动滚轮
js = "window.scrollTo(0,1500)"
driver.execute_script(js)
time.sleep(2)
# 点击规格与包装
driver.find_element_by_xpath("//*[@id=\"detail\"]/div[1]/ul/li[2]").click()
# 解析标签
result_list = []
# 拿取所有的信息Ptable-item
info_elements = driver.find_elements_by_class_name("Ptable-item")
for info_element in info_elements:
# 获取到每一行的笔记本的配置信息
info_element_dict = get_info_element_dict(info_element)
result_list.append(info_element_dict)
# 保存信息到文件
save_goods_info(result_list)
# 将信息保存到mysql
save_goods_tomysql(result_list)
def get_info_element_dict(info_element):
# 主体等
computer_part = info_element.find_element_by_tag_name("h3")
# 系列等
computer_info_keys = info_element.find_elements_by_tag_name("dt")
# 配置信息等
computer_info_values = info_element.find_elements_by_xpath("dl//dd[not(contains(@class,'Ptable-tips'))]")
# 存储计算机中的key,value
key_and_value_dict = {}
# 用来存储所有的计算机组成信息的字典
parts_dict = {}
for i in range(len(computer_info_keys)):
key_and_value_dict[computer_info_keys[i].text] = computer_info_values[i].text
parts_dict[computer_part.text] = key_and_value_dict
return parts_dict
def save_goods_info(result_list):
file_path = os.getcwd() + "/goods_info/"
if not os.path.exists(file_path):
os.mkdir(file_path)
with open(file_path + "computer.infos", "a", encoding="utf-8") as c:
c.write(str(result_list))
print(str(result_list))
if __name__ == "__main__":
driver = webdriver.Chrome("/home/yanjun/Downloads/chromedriver")
driver.maximize_window()
# login(driver)
try:
#用循环控制校验的登录态
loop_status = True
while loop_status:
#校验cookies是否过期
login_status = check_cookies(driver)
if login_status:
loop_status = False
else:
login(driver)
to_thinkpad(driver)
finally:
time.sleep(2)
driver.quit()
import os
import json
def save_cookies(driver):
# 获取本地路径
file_path = os.getcwd()+ "/cookies/"
if not os.path.exists(file_path):
os.mkdir(file_path)
# 保存cookies到文件中
cookies = driver.get_cookies()
with open(file_path + "jd.cookies", "w") as c:
# 这里必须用dump方式写入文件
# 不然你loads的时候会有问题,
# 格式会不匹配
json.dump(cookies, c)
print(cookies)
def check_cookies(driver):
# 初始化login_status
login_status = False
# 将本地cookies装载到driver中
driver = load_local_cookies_to_driver(driver)
# 校验cookies是否过期,未过期则能访问到订单中心
driver.get("https://order.jd.com/center/list.action")
current_url = driver.current_url
if current_url == "https://order.jd.com/center/list.action":
login_status = True
print("cookies校验通过,登录成功")
return login_status
else:
print("登录失败")
return login_status
def load_local_cookies_to_driver(driver):
file_path = os.getcwd() + "/cookies/"
# 读取cookies信息
jd_cookies_str = open(file_path + "jd.cookies", "r").readline()
# 加载cookies信息
jd_cookies_dict = json.loads(jd_cookies_str)
# 这个地方必须先访问一下网站,然后把旧的cookies 删除掉,再把我们保存的cookies添加进去
driver.get("https://www.jd.com/")
driver.delete_all_cookies()
for cookie in jd_cookies_dict:
driver.add_cookie(cookie)
return driver
import pymysql
def save_goods_tomysql(result_list):
# 获取链接
try:
db_conn = get_connection()
# 获取游标
cur = db_conn.cursor()
# 书写sql
for info in result_list:
for key, value in info.items():
# 避免有坑,第一数据必须为元祖,第二数据为string,用引号
sql = "insert into goods(computer_part_name,computer_info) values (\"%s\",\"%s\")" % (key, value)
print(sql)
cur.execute(sql)
db_conn.commit()
# 执行sql
# 提交sql
# 关闭链接
finally:
close_db(db_conn, cur)
def get_connection():
db_conn = pymysql.connect(
host='localhost',
user='root',
password='root',
db='test_db',
charset='utf8')
return db_conn
def close_db(db_conn, cur):
cur.close()
db_conn.close()
\ 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