
python
文章平均质量分 81
fonyer
这个作者很懒,什么都没留下…
展开
-
python mysql
写操作:#安装PyMySQL:pip3 install PyMySQL#!/usr/bin/python3#coding=utf-8 import pymysql # 打开数据库连接db = pymysql.connect("localhost","root","root","mypython" ) # 使用cursor()方法获取操作游标 curs原创 2018-02-01 00:51:47 · 186 阅读 · 0 评论 -
python爬虫之scrapy
环境:centos6 + python3安装:pip3 install scrapy报错:src/twisted/test/raiser.c:4:20: error: Python.h: No such file or directory src/twisted/test/raiser.c:6:6: error: #error Python headers needed to compile...原创 2018-02-11 04:26:55 · 530 阅读 · 0 评论 -
python爬虫之urllib
#coding=utf-8 #urllib操作类 import timeimport urllib.requestimport urllib.parsefrom urllib.error import HTTPError, URLErrorimport sysclass myUrllib: @staticmethod def get_headers(headers):原创 2018-02-05 01:41:59 · 314 阅读 · 0 评论 -
python 数据库操作类
#安装PyMySQL:pip3 install PyMySQL #!/usr/bin/python3 #coding=utf-8 #数据库操作类 from datetime import * import pymysql import hashlibimport timeclass SingletonModel:原创 2018-02-02 03:55:06 · 2782 阅读 · 0 评论 -
python 协程
协程之yield#coding=utf-8import timedef A(): while True: print('---A---') yield time.sleep(0.5)def B(c): while True:原创 2018-01-26 00:11:07 · 151 阅读 · 0 评论 -
python socket编程
UDP协议:#coding=utf-8from threading import Threadfrom socket import *#收数据def receiveData(udpSocket,destIp,destPort): while True: content,destInfo = udpSocket.recvfrom(102原创 2018-01-20 03:35:05 · 243 阅读 · 0 评论 -
python 进程
#fork在window下不支持import osimport timeimport sys pid = os.fork()if pid == 0:#子进程 time.sleep(5) print('After 5 seconds') print('line%d:fork进程%d,PID=%d,父PID=%d'%(sys._get原创 2018-01-10 02:16:53 · 299 阅读 · 0 评论 -
多进程copy文件
from multiprocessing import Pool,Manager import os,time def copyFileTask(fileName,oldFolderName,newFolderName,queue): fr = open(oldFolderName+"/"+fileName,'r',encoding='UTF-8') fw = open(ne原创 2018-01-10 02:27:16 · 212 阅读 · 0 评论 -
python消息队列Queue
实例1:消息队列Queue,不要将文件命名为“queue.py”,否则会报异常“ImportError: cannot import name 'Queue'”#coding=utf-8from multiprocessing import Queue q = Queue(3)#初始化一个Queue对象,最多可接收三条put消息q.put('message-1')q.put('原创 2018-01-10 02:21:34 · 5176 阅读 · 0 评论 -
python 线程
1、线程类import threading import time class MyThread(threading.Thread): """docstring for MyThread""" def run(self): for x in range(2): time.sleep(1) msg = "I'm "+self.name+"@"+str(x) print原创 2018-01-11 23:14:57 · 184 阅读 · 0 评论 -
python3+scrapy 趣头条爬虫实例
项目简介 爬取趣头条新闻(http://home.qutoutiao.net/pages/home.html),具体内容: 1、列表页(json):标题,简介、封面图、来源、发布时间 2、详情页(html):详细内容和图片目录结构 生成的数据文件-单条记录主要代码说明爬虫: #爬取趣头条列表和详情页 qutoutiao.spiders.qutoutiaos.QutoutiaosSpider管道文件...原创 2018-02-16 15:21:00 · 13851 阅读 · 5 评论