From fce0ff43bbbf953c3e8a5bfca7b403018e6777d8 Mon Sep 17 00:00:00 2001 From: lichao <2483469113@qq.com> Date: Tue, 26 Nov 2024 20:18:08 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0demo=EF=BC=8C?= =?UTF-8?q?=E5=9F=9F=E5=90=8D=E6=9F=A5=E8=AF=A2=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/learn_demo.iml | 2 +- .idea/misc.xml | 2 +- basic_learn/input函数.py | 14 ++++++ basic_learn/列表.py | 27 ++++++++++++ basic_learn/占位符.py | 11 +++++ basic_learn/字符串切片.py | 32 ++++++++++++++ basic_learn/字符串方法.py | 33 ++++++++++++++ basic_learn/打印99乘法表.py | 13 ++++++ downloadImage/download_images.py | 55 +++++++++++++++++++++++ downloadImage/image_spilder.py | 56 +++++++++++++++++++++++ getDomain.py | 76 ++++++++++++++++++++++++++++++++ get_Combine.py | 46 +++++++++++++++++++ simple.py | 45 +++++++++++++++++++ 13 files changed, 410 insertions(+), 2 deletions(-) create mode 100644 basic_learn/input函数.py create mode 100644 basic_learn/列表.py create mode 100644 basic_learn/占位符.py create mode 100644 basic_learn/字符串切片.py create mode 100644 basic_learn/字符串方法.py create mode 100644 basic_learn/打印99乘法表.py create mode 100644 downloadImage/download_images.py create mode 100644 downloadImage/image_spilder.py create mode 100644 getDomain.py create mode 100644 get_Combine.py create mode 100644 simple.py diff --git a/.idea/learn_demo.iml b/.idea/learn_demo.iml index 2c80e12..6cb8b9a 100644 --- a/.idea/learn_demo.iml +++ b/.idea/learn_demo.iml @@ -4,7 +4,7 @@ - + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index fa1b4f2..8755c54 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,5 +3,5 @@ - + \ No newline at end of file diff --git a/basic_learn/input函数.py b/basic_learn/input函数.py new file mode 100644 index 0000000..6ad857b --- /dev/null +++ b/basic_learn/input函数.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +@File : input函数.py +@Author : lichao +@Date : 2024/11/19 15:36 +@Software : PyCharm +""" +# input() 函数用于接收用户输入的数据,返回值为字符串类型。 + +name = input('请输入姓名:') +age = input('请输入年龄:') +print(f'姓名:{name},年龄:{age}') + diff --git a/basic_learn/列表.py b/basic_learn/列表.py new file mode 100644 index 0000000..8a65275 --- /dev/null +++ b/basic_learn/列表.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +@File : 列表.py +@Author : lichao +@Date : 2024/11/26 17:06 +@Software : PyCharm +""" + +# 创建列表的两种方式 +# 1.使用[]创建 +list1 = [1,2,3,4,5] + +list1.append(6) + +# 2.使用list()创建 +list2 = list('hello') + +print(list1,list2) + +# 3.使用+ 连接两个列表 +list3 = list1 + list2 +print(list3) + + +# 使用 + 不改变原列表, 使用+= 更改原列表 +# 使用append()改变原列表 \ No newline at end of file diff --git a/basic_learn/占位符.py b/basic_learn/占位符.py new file mode 100644 index 0000000..d607eaf --- /dev/null +++ b/basic_learn/占位符.py @@ -0,0 +1,11 @@ +# 变量占位符 +name = 'lichao' +age = 25 +money = 9.535 + +# 一种用法 +print("姓名:%s,年龄:%d,余额:%.2f" % (name, age, money)) + +#py 3.6以上的版本可以使用 +print(f"姓名:{name},年龄:{age},余额:{money:.2f}") + diff --git a/basic_learn/字符串切片.py b/basic_learn/字符串切片.py new file mode 100644 index 0000000..bcacbf6 --- /dev/null +++ b/basic_learn/字符串切片.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +@File : 字符串切片.py +@Author : lichao +@Date : 2024/11/20 15:41 +@Software : PyCharm +""" + +string = 'abcdef' + +# 左闭右开 +print(string[1:3]) # bc + +print(string[2:]) # cdef + +# 负数索引表示从右往左 +print(string[:-1]) # abcde + +# 省略索引,表示全部 +print(string[:]) # abcdef + +# 步长 第三个参数 ,间隔为 步长 - 1 +print(string[::2]) # ace +print(string[:4:3]) # ad + +# 步长为负数,表示从右往左,开始要大于结束 + +print(string[4:1:-1]) # edc + +# 字符串倒序 +print(string[::-1]) # fedcba \ No newline at end of file diff --git a/basic_learn/字符串方法.py b/basic_learn/字符串方法.py new file mode 100644 index 0000000..e511e63 --- /dev/null +++ b/basic_learn/字符串方法.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +@File : 字符串方法.py +@Author : lichao +@Date : 2024/11/20 16:01 +@Software : PyCharm +""" + +string_data = 'testData' + +print(string_data.find('D',0,1)) # -1 + +print(string_data.count('a')) + +print(string_data.replace('a', 'A',1)) # testDAta + +string_data2 = 'a,b,c,d,e' + +print(string_data2.split(',')) # ['a', 'b', 'c', 'd', 'e'] + +string_data3 = ' hello ' + +print(string_data3.strip()) # hello + +string_data4 = '12313aaa' + +print(string_data4.isdigit()) # false +print(string_data4.isalnum()) # True + +symbol = ',' +strings = ['a','b','c','d','e'] +print(symbol.join(strings)) # a,b,c,d,e \ No newline at end of file diff --git a/basic_learn/打印99乘法表.py b/basic_learn/打印99乘法表.py new file mode 100644 index 0000000..b775674 --- /dev/null +++ b/basic_learn/打印99乘法表.py @@ -0,0 +1,13 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +@File : 打印99乘法表.py +@Author : lichao +@Date : 2024/11/26 17:03 +@Software : PyCharm +""" + +for i in range(1, 10): + for j in range(1, i + 1): + print(f' {i * j}', end=' ') + print() \ No newline at end of file diff --git a/downloadImage/download_images.py b/downloadImage/download_images.py new file mode 100644 index 0000000..6aed5f1 --- /dev/null +++ b/downloadImage/download_images.py @@ -0,0 +1,55 @@ +import requests +import os +import math +from dotenv import load_dotenv + +load_dotenv() +# 获取用户输入的 API 密钥和搜索关键字 +search_query = input("请输入你想搜索的图片类型:") +total_images = int(input("请输入你想下载的图片数量:")) + +# 设置基本参数 +params = { + 'key': os.getenv('API_KEY'), + 'q': search_query, + 'image_type': 'photo', + 'pretty': 'true', + 'per_page': 200 # 每页最多下载 200 张图片 +} + +# 计算需要的页数 +images_per_page = params['per_page'] +num_pages = math.ceil(total_images / images_per_page) + +# 创建保存图片的目录 +save_dir = f'./Pixabay_{search_query}_Images' +if not os.path.exists(save_dir): + os.makedirs(save_dir) + +# 定义函数用于下载每页的图片 +def download_images(page_number, remaining_images): + params['page'] = page_number + response = requests.get('https://pixabay.com/api/', params=params) + data = response.json() + + if 'hits' in data: + for i, image in enumerate(data['hits']): + if remaining_images <= 0: + break + img_url = image['webformatURL'] + img_data = requests.get(img_url).content + img_path = os.path.join(save_dir, f"{search_query}_page_{page_number}_img_{i + 1}.jpg") + with open(img_path, 'wb') as file: + file.write(img_data) + remaining_images -= 1 + print(f"已下载:{img_path}") + else: + print(f"在第 {page_number} 页没有找到相关图片。") + return remaining_images + +# 下载图片直到总数达到用户指定的数量 +remaining_images = total_images +for page in range(1, num_pages + 1): + remaining_images = download_images(page, remaining_images) + if remaining_images <= 0: + break \ No newline at end of file diff --git a/downloadImage/image_spilder.py b/downloadImage/image_spilder.py new file mode 100644 index 0000000..a8885ab --- /dev/null +++ b/downloadImage/image_spilder.py @@ -0,0 +1,56 @@ +import os +import requests +from bs4 import BeautifulSoup +from urllib.parse import urljoin + + +# 创建保存图片的目录 +def create_directory(directory): + if not os.path.exists(directory): + os.makedirs(directory) + + +# 下载图片 +def download_image(url, folder_path): + try: + response = requests.get(url, stream=True) + if response.status_code == 200: + # 从URL中获取文件名 + filename = os.path.join(folder_path, url.split("/")[-1]) + with open(filename, 'wb') as file: + for chunk in response.iter_content(1024): + file.write(chunk) + print(f"图片下载成功: {filename}") + else: + print(f"图片下载失败: {url}") + except Exception as e: + print(f"下载过程中出现错误: {e}") + + +# 爬取网页中的图片 +def scrape_images(url, folder_path="downloaded_images"): + create_directory(folder_path) + + # 发送HTTP请求获取网页内容 + response = requests.get(url) + soup = BeautifulSoup(response.text, 'html.parser') + + # 查找所有标签 + img_tags = soup.find_all('img') + + # 遍历所有图片标签,获取图片URL并下载 + for img in img_tags: + img_url = img.get('src') + if not img_url: + continue + + # 转换为绝对URL(有些网站使用相对路径) + img_url = urljoin(url, img_url) + + # 下载图片 + download_image(img_url, folder_path) + + +# 示例使用 +url = "https://lcdd.net" # 你想要爬取的网页URL +scrape_images(url) diff --git a/getDomain.py b/getDomain.py new file mode 100644 index 0000000..5b891c0 --- /dev/null +++ b/getDomain.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +@File : getDomain.py +@Author : lichao +@Date : 2024/11/25 16:09 +@Software : PyCharm +""" + +import whois +import concurrent.futures +from get_Combine import generate_combinations + + +def check_domain_registration(domain): + try: + # 使用 whois 查询域名信息 + domain_info = whois.whois(domain) + + # 如果是 .de 域名,直接检查 Status 字段 + if domain.endswith(".de"): + status_line = domain_info.get('status', '').lower() + if 'free' in status_line: + return (domain, False) # 域名未注册 + else: + return (domain, True) # 域名已注册 + + # 判断返回的数据是否为空,通常空数据表示域名未注册 + if domain_info is None or not domain_info.domain_name: + return (domain, False) + else: + return (domain, True) + + except Exception as e: + # 捕获任何异常并处理未注册的情况 + return (domain, False) + + +def check_domains_in_parallel(domains): + results = [] + + # 使用 ThreadPoolExecutor 进行并行查询 + with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor: + # 提交所有查询任务 + future_to_domain = {executor.submit(check_domain_registration, domain): domain for domain in domains} + + # 获取查询结果 + for future in concurrent.futures.as_completed(future_to_domain): + domain = future_to_domain[future] + try: + result = future.result() + results.append(result) + except Exception as exc: + print(f"{domain} 产生了一个异常: {exc}") + + return results + +# strings = generate_combinations(1,'.de') +# +# print(len(strings),strings) + +# 测试例子 +domains_to_check = [ + ".de", +] + +# 并行查询 +results = check_domains_in_parallel(domains_to_check) + +# 打印结果 +for domain, is_registered in results: + if is_registered: + print(f"域名 {domain} 已被注册。") + else: + print(f"域名 {domain} 未被注册。") + diff --git a/get_Combine.py b/get_Combine.py new file mode 100644 index 0000000..849c4d3 --- /dev/null +++ b/get_Combine.py @@ -0,0 +1,46 @@ +from itertools import combinations + + +def generate_combinations(n, suffix): + # 所有可能的单个字母 + letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + + # 对 n=1 的特殊处理 + if n == 1: + return [c + suffix for c in letters] + + # 1. n 个字母完全相同的组合 + repeated_combinations = [c * n for c in letters] + + # 2. (n-1) 个字母相同,一个不同的组合 (仅当 n > 1) + double_repeats = [] + if n > 1: + for c1 in letters: + for c2 in letters: + if c1 != c2: + # 确保字母按字母表顺序排列,避免重复 + combination = ''.join(sorted([c1] * (n - 1) + [c2])) + if combination not in double_repeats: + double_repeats.append(combination) + + # 3. n 个字母不完全相同的组合 (仅当 n > 1) + unique_combinations = [] + if n > 1: + unique_combinations = [''.join(sorted(comb)) for comb in combinations(letters, n) if len(set(comb)) == n] + + # 合并所有组合 + all_combinations = repeated_combinations + double_repeats + unique_combinations + + # 将所有组合拼接后缀 + final_combinations = [combo + suffix for combo in all_combinations] + + return final_combinations + +if __name__ == '__main__': + n = 2 # 可以输入不同的长度 + suffix = '.de' # 可以输入不同的后缀 + + # 生成组合并打印 + combinations = generate_combinations(n, suffix) + print(combinations) + print(f"生成的组合数量: {len(combinations)}") diff --git a/simple.py b/simple.py new file mode 100644 index 0000000..0f9ba6e --- /dev/null +++ b/simple.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +@File : simple.py +@Author : lichao +@Date : 2024/11/25 16:39 +@Software : PyCharm +""" + +import requests +import string + + +def gen_combos(): + chars = string.ascii_lowercase + string.digits + combos = [] + for char1 in chars: + for char2 in chars: + for char3 in chars: + combos.append(char1 + char2 + char3) + return combos + + +def find(base_url, combos): + for combo in combos: + url = f"{base_url}{combo}.de" + print(combo, end="") + try: + response = requests.get(url) + if "is free and available for registration." in response.text: + print(".de 可注册") + else: + print() + except requests.RequestException as e: + print(e) + + +def main(): + base_url = "https://webwhois.denic.de/?lang=en&query=" + combos = gen_combos() + find(base_url, combos) + + +if __name__ == "__main__": + main() \ No newline at end of file