feat: 增加demo,域名查询代码
This commit is contained in:
parent
120df8ea49
commit
fce0ff43bb
|
|
@ -4,7 +4,7 @@
|
||||||
<content url="file://$MODULE_DIR$">
|
<content url="file://$MODULE_DIR$">
|
||||||
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="jdk" jdkName="Python 3.12" jdkType="Python SDK" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
|
|
@ -3,5 +3,5 @@
|
||||||
<component name="Black">
|
<component name="Black">
|
||||||
<option name="sdkName" value="Python 3.9 (learn_demo)" />
|
<option name="sdkName" value="Python 3.9 (learn_demo)" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (learn_demo)" project-jdk-type="Python SDK" />
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12" project-jdk-type="Python SDK" />
|
||||||
</project>
|
</project>
|
||||||
|
|
@ -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}')
|
||||||
|
|
||||||
|
|
@ -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()改变原列表
|
||||||
|
|
@ -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}")
|
||||||
|
|
||||||
|
|
@ -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
|
||||||
|
|
@ -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
|
||||||
|
|
@ -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()
|
||||||
|
|
@ -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
|
||||||
|
|
@ -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>标签
|
||||||
|
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)
|
||||||
|
|
@ -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} 未被注册。")
|
||||||
|
|
||||||
|
|
@ -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)}")
|
||||||
|
|
@ -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()
|
||||||
Loading…
Reference in New Issue