Python网络爬虫
网站爬取 import requests url = "https://www.bilibili.com/?spm_id_from=666.6.b_62616e6e65725f6c696e6b.12" try: r = requests.get(url) r.raise_for_status() r.encoding = r.apparent_encoding print(r.text) exce…
网站爬取 import requests url = "https://www.bilibili.com/?spm_id_from=666.6.b_62616e6e65725f6c696e6b.12" try: r = requests.get(url) r.raise_for_status() r.encoding = r.apparent_encoding print(r.text) exce…
题目描述 给你一棵二叉树的根节点 root ,找出并返回满足要求的节点数,要求节点的值等于其 子树 中值的 平均值 。 注意: n 个元素的平均值可以由 n 个元素 求和 然后再除以 n ,并 向下舍入 到最近的整数。 root 的 子树 由 root 和它的所有后代组成。 Coding # Definition for a binary tree node. # class TreeNode: …
题目 给定字符串s,请找到字符串s中最长的回文子串 如: s = “badadb” 的回文子串str 为 “ada”. s = "w" , str = "w", s = "qe", str = "q"。 解题思路 首先我们要理解, 何为最长回文子串?通俗点讲,回文子串就是字符串关于中点(字符)对称,左右两边长的一样。将字符串倒序后仍是原来的字符串。 说到这里我们不得不提一下苏轼一首有名的回文诗。 …
#!/usr/bin/env python # -*- coding: utf-8 -*- import re Name = "_admin" NUM_LETTER = re.compile("^(?!\d+$)[\da-zA-Z_]+$") #数字和字母组合,不允许纯数字 FIRST_LETTER = re.compile("^[a-zA-Z]") #只能以字母开头 def account_na…
import urllib.request def down_url(data_url,file_name): print("{} Downloading....".format(file_name)) urllib.request.urlretrieve(data_url, file_name) print("{} Done!!".format(file_name)) def main(): d…
这篇文章主要介绍了Python使用微信接入图灵机器人过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 1.wxpy库介绍 wxpy 在 itchat 的基础上,通过大量接口优化提升了模块的易用性,并进行丰富的功能扩展。 文档地址: https://wxpy.readthedocs.io 从 PYPI 官方源下载安装 pip install …
作业要求:根据已知圆的半径radius(从控制台上输入),求其面积和周长(PI可以使用math.pi,也可以使用3.14) 代码如下: import math radius = float(input("请输入圆的半径:")) area = math.pi * radius ** 2 circumference = 2 * math.pi * radius print("圆的面积:", area)…
各种图形代码 1.堆积面积图 import numpy as np import matplotlib.pyplot as plt x = np.arange(6) y1 = np.array([1,2,3,4,5,6]) y2 = np.array([1,3,5,7,9,4]) y3 = np.array([2,4,7,8,9,5]) plt.stackplot(x, y1, y2, y3) p…
额 我把时间全部化成秒。等待时间=早到时间+等前一个人完事时间 我是将所有早到时间先加起来,然后这些人全部归于8点开始。 用time按开始时间排列出所有有效的排队人。用pcs按所需时间排列出所有已经在窗口的人。 等前一个人完事时间=pcs中前一个人的结束时间-time中这个人的开始时间 n, k = list(map(int, input().split())) time = [] sec = 0…