
python基础
丶小石
这个作者很懒,什么都没留下…
展开
-
cannot import name ‘webdriver‘ from ‘selenium‘
最近在学习爬虫,使用selenium来爬取网页,第一次使用 pip install selenium 下载这个模块 。当是我第二天使用就给我报这个错误ImportError:cannot import name 'webdriver' from 'selenium'原因也很简单 ,是因为我新建的名称叫selenium.py,导致Python会先导入这个文件,然后再导入标准库里面的selenium.py只需要把自己的重命名,或者删除就okk...原创 2020-08-05 14:45:23 · 1623 阅读 · 1 评论 -
python连接mongoDB,进行增删改查操作
1.下载mongo的驱动模块:python -m pip install pymongo2.创建连接,指定数据库,指定集合#mongoDBimport pymongoclient=pymongo.MongoClient('mongodb://localhost:27017')client#指定数据库db=client.testdb#指定集合collection=db.studentscollection3.插入数据#插入数据student={ 'id':'原创 2020-07-31 00:55:52 · 399 阅读 · 0 评论 -
python连接mysql,进行增删改查基本操作
1.先安装mysql模块 pip install pymysql2.import mysql3.创建一张表pymysql.paramstyle='format'db=pymysql.connect("localhost","root","A","test")cursor=db.cursor()cursorsql="""CREATE TABLE EMPLOYEE ( FIRST_NAME CHAR(20) NOT NULL, LAST_NAME CHA.原创 2020-07-30 09:08:31 · 270 阅读 · 0 评论 -
python实现一个伪随机数生成器
伪随机数生成的方法有很多 1.平方取中法 2.线性同余法 这里介绍线性同余法: 公式 rNew=(a*rOld+b)%(end-start) 1. a称为乘数,b称为增量,(end-start)称为模数,它们均为常数 2.然后设置rOld=rNew ,一般要求用户指定种子数rOld(也叫seed),当然也可以自由选择a和b 但是这两个数如果选择不好,可能会影响数字的随机性 a=4p+1 b=2q+1 最好def myrandint(start,end,see...原创 2020-07-29 16:09:09 · 1773 阅读 · 0 评论