首页
学习
活动
专区
工具
TVP
发布

玩转编程

一起玩转编程
专栏作者
41
文章
12895
阅读量
15
订阅数
Python 系列文章 —— numpy 详解
numpy from numpy import * import numpy as np # numpy 简单运用实例 print(eye(4)) # 创建简单的 ndarray 对象 a = np.array([1, 2, 3]) print(a) # 创建大于 1 维的数组 使用 ndmin 参数,ndmin 参数默认值为0 b = np.array([1, 2, 3], ndmin=2) print(b) b1 = np.array([2, 3, 4],ndmin=-1) print(b1)
玩转编程
2022-01-15
2160
Python 系列文章 —— Python 操作 MySQL 详解
create_table import pymysql # 打开数据库连接 conn = pymysql.connect( host="127.0.0.1", user="root", password="123456", database="test_db", charset="utf8") # 获取连接下的游标 cursor_test = conn.cursor() # 使用 execute() 方法执行 SQL,如果表存在则删除 cursor_test.e
玩转编程
2022-01-15
1920
Python 系列文章 —— Python 操作 mongodb 详解
mongodb #导入 MongoClient 模块 from pymongo import MongoClient, ASCENDING, DESCENDING # 两种方式 #1. 传入数据库IP和端口号 mc = MongoClient('127.0.0.1', 27017) #2. 直接传入连接字串 mc = MongoClient('mongodb://127.0.0.1:27017') # 有密码的连接 # 首先指定连接testdb数据库 # db = mc.testdb # 通过aut
玩转编程
2022-01-15
2490
Python 系列文章 —— sqlite 详解
sqlite_demo 导入模块 mport sqlite3 连接数据库 onn = sqlite3.connect('test.db') 创建游标 s = conn.cursor() 创建表 cs.execute('''CREATE TABLE student (id varchar(20) PRIMARY KEY, name varchar(20));''') 关闭 Cursor cs.close() 提交 conn.commit() 关闭连接
玩转编程
2022-01-15
2360
Python 系列文章 —— renren 实战
github import scrapy import re class GithubSpider(scrapy.Spider): name = 'github' allowed_domains = ['github.com'] # 登录页面 URL start_urls = ['https://github.com/login'] def parse(self, response): # 获取请求参数 commit = respo
玩转编程
2022-01-15
3280
Python 系列文章 —— WxCrawler
WxCrawler # coding:utf-8 import requests import re import html import demjson import json from bs4 import BeautifulSoup import urllib3 class WxCrawler(object): urllib3.disable_warnings() #Hearders,x-wechat-key 会过期,会出验证问题 headers = """Connect
玩转编程
2022-01-15
2320
Python 系列文章 —— Python redis 详解
redis import redis #导入redis模块 # 建议使用以下连接池的方式 # 设置decode_responses=True,写入的KV对中的V为string类型,不加则写入的为字节类型。 pool = redis.ConnectionPool(host='127.0.0.1', port=6379, db=0, decode_responses=True) rs = redis.Redis(connection_pool=pool) # key="color",value="red
玩转编程
2022-01-15
3160
Python 系列文章 —— 新闻抓取
demo import newspaper # 词频统计库 import collections # numpy库 import numpy as np # 结巴分词 import jieba # 词云展示库 import wordcloud # 图像处理库 from PIL import Image # 图像展示库 import matplotlib.pyplot as plt # 获取文章 article = newspaper.Article('https://news.sina.com.cn/o/
玩转编程
2022-01-15
5900
Python 系列文章 —— crawlerdb
crawlerdb import mysql.connector import pymysql from pyspider.result import ResultWorker class crawlerdb: conn = None cursor = None def __init__(self): self.conn = pymysql.connect("127.0.0.1", "root", "12345678", "crawler")
玩转编程
2022-01-15
1680
Python 系列文章 —— FBP_Scrapy 项目实战
FBP_Scrapy import datetime import sys import requests import scrapy import time import json import s
玩转编程
2022-01-15
2030
Python 系列文章 —— itemcsvexporter
itemcsvexporter from scrapy.conf import settings # from scrapy.contrib.exporter import CsvItemExporter from scrapy.exporters import CsvItemExporter #指定输出到csv文件中字段的顺序,结合setting.py class itemcsvexporter(CsvItemExporter): def __init__(self, *args, **kwarg
玩转编程
2022-01-15
2430
Python 系列文章 —— selenium 详解
selenium-browser-back-forward from selenium import webdriver import time # 声明浏览器对象 driver = webdriver.Chrome() # 访问百度 driver.get("http://www.baidu.com") time.sleep(2) # 访问微博 driver.get("https://weibo.com") time.sleep(2) # 访问知乎 driver.get("http://www.zhihu
玩转编程
2022-01-15
3140
Python 系列文章 —— BeautifulSoup 实战
BeautifulSoup 实战 from bs4 import BeautifulSoup html_doc = """ <html><head><title>index</title></head> <body> <p class="title"><b>首页</b></p> <p class="main">我常用的网站 <a href="https://www.google.com" class="website" id="google">Google</a> <a href="https://www
玩转编程
2022-01-15
2390
Python 系列文章 —— BeautifulSoup 详解
BeautifulSoup.py from bs4 import BeautifulSoup # demo 1 # soup = BeautifulSoup(open("index.html")) soup = BeautifulSoup("<html><head><title>index</title></head><body>content</body></html>", "lxml") print(soup.head) html_doc = """ <html><head><title>inde
玩转编程
2022-01-15
2190
Python 系列文章 —— lxml 详解
lxml.py from lxml import etree from io import StringIO test_html = ''' <html> <body> <div> <!-- 这里是注释 --> <h4>手机品牌商<span style="margin-left:10px">4</span></h4> <ul> <li>小米</li>
玩转编程
2022-01-13
3170
Python 系列文章 —— flask 表单案例
app.py from flask import Flask, render_template, redirect, url_for, request from flask_wtf import FlaskForm from wtforms import StringField, PasswordField from wtforms.validators import DataRequired, EqualTo from werkzeug.security import generate_passwor
玩转编程
2022-01-13
5260
Python 系列文章 —— 爬虫小案例
Example_Request # 采用 HTTP GET 请求的方法模拟谷歌浏览器访问网站,输出响应上下文 from urllib import request,parse url = 'http://www.python.org' headers = { 'User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/
玩转编程
2022-01-13
2440
Python 系列文章 —— trafficLight
trafficLight import threading import time event = threading.Event() def drive(name): i = 0 while True: i = i + 1 print(name + "正在行驶中,行驶了" + str(i * 60) + "Km") time.sleep(1) event.wait() print(name + "通过了红
玩转编程
2022-01-13
1690
Python 系列文章 —— 线程池
threadpool-demo import time import threadpool import threading def sayhello(name): print("%s say Hello to %s" % (threading.current_thread().getName(), name)); time.sleep(1) return name def callback(request, result): # 回调函数,用于取回结果 print("c
玩转编程
2022-01-13
1870
Python 系列文章 —— queue
queue_common_function_demo import queue q = queue.Queue() q.put(100) q.put(200) q.qsize() # 获取队列大小,此处结果为 2 import queue q = queue.Queue(maxsize=1) q.empty() # 判断队列是否空,此处结果为 True q.full() # 判断队列是否满,此处结果为 False q.put(100) q.empty() # False q.full() # True
玩转编程
2022-01-13
2580
点击加载更多
社区活动
腾讯技术创作狂欢月
“码”上创作 21 天,分 10000 元奖品池!
Python精品学习库
代码在线跑,知识轻松学
博客搬家 | 分享价值百万资源包
自行/邀约他人一键搬运博客,速成社区影响力并领取好礼
技术创作特训营·精选知识专栏
往期视频·千货材料·成员作品 最新动态
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档