搜索到与相关的文章
Python

Python使用一行代码获取上个月是几月

本文介绍的关于Python时间日期处理,日期时间处理在实际应用场景中无处不在,所以这也成了编程语言中必不可少的模块,Python也不例外。但是,你知道在Python中有多少个相关的模块吗?datetime、time、calendar、dateutil、pytz等等。你知道有多少种数据类型吗?date、time、datetime、tzinfo、timedelta等等。有天我遇到这样的需求,想获取当前月的前一个月是几月,假设本月是2018年1月,那么上个月就是

系统 2019-09-27 17:46:11 2186

Python

python scrapy爬虫代码及填坑

涉及到详情页爬取目录结构:kaoshi_bqg.pyimportscrapyfromscrapy.spidersimportRulefromscrapy.linkextractorsimportLinkExtractorfrom..itemsimportBookBQGItemclassKaoshiBqgSpider(scrapy.Spider):name='kaoshi_bqg'allowed_domains=['biquge5200.cc']start_

系统 2019-09-27 17:46:11 2186

Python

Python2中的raw_input() 与 input()

这两个均是python的内建函数,通过读取控制台的输入与用户实现交互。但他们的功能不尽相同。举两个小例子。>>>raw_input_A=raw_input("raw_input:")raw_input:abc>>>input_A=input("Input:")Input:abcTraceback(mostrecentcalllast):File"",line1,ininput_A=input("Input:")File"",line1,inNameErro

系统 2019-09-27 17:45:44 2186

Python

Python3.6+selenium2.53.6自动化测试

环境:编辑工具:浏览器:有问题可以联系qq:1776376537#coding:utf-8fromcommon.baseimportBasefromseleniumimportwebdriverfromselenium.webdriver.common.action_chainsimportActionChainsfromselenium.webdriver.support.selectimportSelect#打开火狐浏览器driver=webdrive

系统 2019-09-27 17:45:33 2186

Python

python实现的config文件读写功能示例

本文实例讲述了python实现的config文件读写功能。分享给大家供大家参考,具体如下:1、设置配置文件[mysql]host=1234port=3306user=rootpassword=Zhsy08241128database=leartd2、读取配置文件importconfigparserimportosconf=configparser.ConfigParser()defreadConf():'''读取配置文件'''root_path=os.pa

系统 2019-09-27 17:38:38 2186

Python

Python MongoDB 插入数据时已存在则不执行,不存在则插入的解决方法

本文实例讲述了PythonMongoDB插入数据时已存在则不执行,不存在则插入的解决方法。分享给大家供大家参考,具体如下:前言:想把QQ日志爬虫(Python)爬下来的日志保存到MongoDB里面。但insert的时候报错:E11000duplicatekeyerrorcollection:QQ.Blogindex:_id_dupkey:{:"965464518_1301232446"}后来知道错误的原因是:插入的数据和已有数据的ID重复了。我想要的是:插

系统 2019-09-27 17:38:32 2186

Python

Python判断变量是否已经定义的方法

Python判断变量是否已经定义是一个非常重要的功能,本文就来简述这一功能的实现方法。其实Python中有很多方法可以实现判断一个变量是否已经定义了。这里就举出最常用的两种作为示例,如下所示:方法一:tryexcept方法:defisset(v):try:type(eval(v))except:return0else:return1用法:ifisset('user_name'):print'user_nameisdefined'elseprint'user

系统 2019-09-27 17:38:31 2186

Python

python套接字流重定向实例汇总

将套接字流重定向到标准输入或输出流#!/usr/bin/envpython3"""测试socket-stream重定向模式"""importsys,os,timefrommultiprocessingimportProcessfromsocketimport*definitListenerSocket(port=50008,host=''):"""初始化在服务器模式下调用者用于监听连接的套接字"""sock=socket()try:sock.bind((h

系统 2019-09-27 17:38:28 2186

Python

python 爬取微信文章

本人想搞个采集微信文章的网站,无奈实在从微信本生无法找到入口链接,网上翻看了大量的资料,发现大家的做法总体来说大同小异,都是以搜狗为入口。下文是笔者整理的一份python爬取微信文章的代码,有兴趣的欢迎阅读#coding:utf-8author='haoning'**#!/usr/bin/envpythonimporttimeimportdatetimeimportrequests**importjsonimportsysreload(sys)sys.se

系统 2019-09-27 17:38:27 2186

Python

python字符类型的一些方法小结

int数字类型classint(object):"""int(x=0)->intorlongint(x,base=10)->intorlongConvertanumberorstringtoaninteger,orreturn0ifnoargumentsaregiven.Ifxisfloatingpoint,theconversiontruncatestowardszero.Ifxisoutsidetheintegerrange,thefunctionre

系统 2019-09-27 17:38:22 2186