小白初学 Python ,有没有大佬可以帮忙简化一下代码
source link: https://www.v2ex.com/t/791165
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
import openpyxl
#用来保存结果的列表
two = []
urltwo = []
urltwoo = []
three = []
urlthree = []
urlthreee = []
four = []
urlfour = []
urlfourr = []
five = []
urlfive = []
urlfivee = []
letters = "abcdefghijklmnopqrstuvwxyz"
#几位数,自己定
ttwo = [a+b for a in letters for b in letters]
tthree = [a+b+c for a in letters for b in letters for c in letters]
ffour = [a+b+c+d for a in letters for b in letters for c in letters for d in letters]
ffive = [a+b+c+d+e for a in letters for b in letters for c in letters for d in letters for e in letters]
#域名后缀
hz = "logistics.com.br"
hz2 = "comex.com"
#开始
for k2 in ttwo:
url2 = [k2 + hz]
url22 = [k2 + hz2]
urltwo.append(url2)
urltwoo.append(url22)
two = urltwo + urltwoo
for k3 in tthree:
url3 = [k3 + hz]
url33 = [k3 + hz2]
urlthree.append(url3)
urlthreee.append(url33)
three = urlthree + urlthreee
for k4 in ffour:
url4 = [k4 + hz]
url44 = [k4 + hz2]
urlfour.append(url4)
urlfourr.append(url44)
four = urlfour + urlfourr
for k5 in ffive:
url5 = [k5 + hz]
url55 = [k5 + hz2]
urlfive.append(url5)
urlfivee.append(url55)
five = urlfive + urlfivee
#导出结果
data = {'两个字母': two,'三个字母': three,'四个字母': four,'五个字母':five}
frame = pd.DataFrame(data)
frame.to_excel("E:\BaiduNetdiskWorkspace\个人\python\猜域名.xlsx")
第 1 条附言 · 1 天前
#问题 1:不知道怎么处理 letter_permutations 才能组成 ab,ac,ad 这样的组合
#问题 2:怎么才能去掉生成的 excel 第一列默认的数字索引
import string
import itertools
import pandas as pd
import openpyxl
import requests
import sys
#Lowercase_alphabet,小写字母表
Lowercase_alphabet = string.ascii_lowercase
url = []
result_url = []
#定义一个函数来生成 url
def web_guessing(n,domain)
n = input('请输入你想生成几位数的组合')
domain = raw_input('请输入你想组合的域名')
letter_permutations = list(itertools.permutations(Lowercase_alphabet,n))
#不知道怎么处理 letter_permutations 才能组成 ab,ac,ad 这样的字符串组合
#将字母组合和域名组成网址
for permutations in letter_permutations:
url = [permutations+domain]
#检测状态码,储存有效的 url
r=requests.get(url,timeout=5)
code = r.status_code
if code == 200:
result_url.append(url)
#进行数据转换,输出到 excel
data = {'%d位字母的域名组合'%n : result_url}
frame = pd.DataFrame(data)
frame.to_excel("E:\BaiduNetdiskWorkspace\个人\python\域名\猜域名.xlsx")
return("结果保存在:E:\BaiduNetdiskWorkspace\个人\python\域名\猜域名.xlsx")
Recommend
-
67
点击上方“程序员大咖”,选择“置顶公众号” 关键时刻,第一时间送达! ...
-
40
Go诞生于Google, 是由以下三位计算机领域的大师写的 image 由于出身名门,Go在诞生之初就吸引...
-
31
游戏 - @mary9 - 本人游戏小白,因为最近要入一个游戏公司,不知道有没有打游戏很厉害的需求,心里好慌啊~(不要问我为啥一个游戏公司要我这个游戏小白,我也不知道,他面试的时候并没有说需要打游戏很厉害的。所以心里很害怕,想提
-
41
求职 - @sayhe110 - # 个人信息* ##/男 /1996* 学历:本科* 期望职位:PHP 工程师* 手机:####* Email:####* QQ/微信号:####* 博客: http:
-
8
发展高端科学仪器 上海可以有大作为 来源:解放日报2021-02-20 13:50...
-
1
为什么初学编程我建议从Python开始 – Tinyfool的个人网站从1992年算起,我写程序已经写了28年,从2001年上班算起,我写程序也写了19年了。编程最早就是我的一个爱好,然后整个职业生涯编程养活了我,让我过了一个还不错的生活。到了这些年,我写文章的收入日益...
-
5
V2EX › Go 编程语言 初学 golang,小白求解惑! superfatboy · 17 小时 12 分钟前 · 1...
-
4
V2EX › Kubernetes CF 的 worker 有大佬可以针对 K8S 做点配置样板吗? Infinitify · 3 小时...
-
4
V2EX › 程序员 eslint 自定义插件 - 有大佬帮忙看下吗 yiluo · 7 小时 25 分钟前 · 162 次...
-
6
V2EX › 程序员 有大佬可以推荐一款可以碎片化时间记单词的 App 吗
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK