图片 2

用PHP读注册表

$shell = new COM(“WScript.Shell”) or die(“This thing requires Windows
Scripting Host”);$registry_proxystring =
$shell-RegRead(“HKEY_CURRENT_USER//Software//Microsoft//Windows//CurrentVersion//Internet
Settings//ProxyServer”);同样可以用RegWrite方法写入如果有问题,请参考相关资源:[url];en-us;Q221081[/url]

图片 1

要求:抓取喜马拉雅音频存储到本地 D:temp_ximalaya_audio,并按节目和章节分类存储。

前言

特殊说明:分析思路参考

本篇整理信息收集阶段,大概会占渗透测试总时间的60%,视能力和情况而定,做到不影响企业业务正常运行的情况下,收集更多的资产信息,细心和耐心很关键。

__author__ =’tony’

主站

import json

快速定位,快速产出

import random

先浏览下主站,可以很直观的了解目标站点的大致业务/性质/模式,会对整个渗透过程起到很大的帮助。

import time

对于boss要求的部分站点需要快速产出漏洞(销售好谈客户),主站很多都是可以拿下的,比如四位数字无限制爆破验证码,sqli,备份文件,组件框架历史漏洞,后台弱口令,邮箱收集/爆破/社工theHarvester等等。

import urllib.request

对于无范围全网测的厂商,可通过以下途径获取相关资产,比如收集开发运维专用的域名和解析到内网的域名,主机ip所属等。

import pymongo

搜索引擎hacking语法,搜target.com|公司名字,有时也能查到,但是数据需要清洗。

import requests

whois查询/注册人反查/邮箱反查/相关资产

import aiohttp

站长之家

import asyncio

爱站

from bs4import BeautifulSoup

微步在线(企业版)

from lxmlimport etree

ip反查

import os

天眼查

import shutil

虎妈查

filePath =”D:\temp_ximalaya_audio”

历史漏洞查询

channelFilePath =””

Github泄露

# 初始化文件目录

本阶段收集的信息,为下一步收集/爆破子域名做好准备。

if os.path.isdir(filePath):

子域名

shutil.rmtree(filePath)# 递归删除目录树

子域名的收集途径很多,Layer子域名挖掘机4.2纪念版,subDomainsBrute李劼杰,wydomain猪猪侠,Sublist3r,site:target.com,Github代码仓库,抓包分析请求返回值(跳转/文件上传/app/api接口等),站长帮手links等在线查询网站,部分会受到泛解析的影响,记录下学习到的,

elif os.path.isfile(filePath):

域传送漏洞

os.remove(filePath)# 删除文件

linux:

os.makedirs(filePath)# 创建目录

[dig @ns.example.com example=.com AXFR]

# mongodb

windows:

#clients = pymongo.MongoClient(‘localhost’)

[nslookup -> set type=ns ->target.com -> server ns.target.com
-> ls target.com]

#db = clients[“XiMaLaYa”]

GetDomainsBySSL

#col1 = db[“album2”]

censys.io证书

#col2 = db[“detaile2”]

crt.sh证书查询

UA_LIST = [

shodan/fofa.so/zoomeye

“Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like
Gecko) Chrome/22.0.1207.1 Safari/537.1”,

dnsdb.io

“Mozilla/5.0 (X11; CrOS i686 2268.111.0) AppleWebKit/536.11 (KHTML, like
Gecko) Chrome/20.0.1132.57 Safari/536.11”,

api.hackertarget

“Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.6 (KHTML, like
Gecko) Chrome/20.0.1092.0 Safari/536.6”,

community.riskiq.com

“Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.6 (KHTML, like Gecko)
Chrome/20.0.1090.0 Safari/536.6”,

n级子域名爆破

“Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.1 (KHTML, like
Gecko) Chrome/19.77.34.5 Safari/537.1”,

subdomain3

“Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/536.5 (KHTML, like Gecko)
Chrome/19.0.1084.9 Safari/536.5”,

FuzzDomain

“Mozilla/5.0 (Windows NT 6.0) AppleWebKit/536.5 (KHTML, like Gecko)
Chrome/19.0.1084.36 Safari/536.5”,

端口服务

“Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.3 (KHTML, like
Gecko) Chrome/19.0.1063.0 Safari/536.3”,

假设从layer导出来的子域名列表为target.com.txt,使用nmap扫默认端口

“Mozilla/5.0 (Windows NT 5.1) AppleWebKit/536.3 (KHTML, like Gecko)
Chrome/19.0.1063.0 Safari/536.3”,

nmap -v -A -F -iL target.com.txt -oX target_f.xml

“Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; SE 2.X
MetaSr 1.0; SE 2.X MetaSr 1.0; .NET CLR 2.0.50727; SE 2.X MetaSr 1.0)”,

扫描全端口

“Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.3 (KHTML, like Gecko)
Chrome/19.0.1062.0 Safari/536.3”,

nmap -v -A -p1-65535 -iL target.com.txt -oX target_all.xml

“Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.3 (KHTML, like
Gecko) Chrome/19.0.1062.0 Safari/536.3”,

端口扫描脚本

“Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.3 (KHTML, like
Gecko) Chrome/19.0.1061.1 Safari/536.3”,

端口渗透总结

“Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.3 (KHTML, like Gecko)
Chrome/19.0.1061.1 Safari/536.3”,

web探测

“Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.3 (KHTML, like Gecko)
Chrome/19.0.1061.0 Safari/536.3”,

探测每个站点的web信息,假设所有子域名都在:target.com_domains.txt(Layer直接导出域名)

“Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.24 (KHTML, like Gecko)
Chrome/19.0.1055.1 Safari/535.24”,

BSDR_Banners密码:rzv0

“Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/535.24 (KHTML, like
Gecko) Chrome/19.0.1055.1 Safari/535.24”,

web指纹识别

“Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like
Gecko) Chrome/22.0.1207.1 Safari/537.1”,

邮箱命名规则收集/爆破/社工

“Mozilla/5.0 (X11; CrOS i686 2268.111.0) AppleWebKit/536.11 (KHTML, like
Gecko) Chrome/20.0.1132.57 Safari/536.11”,

详细可参考:渗透标准

“Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.6 (KHTML, like
Gecko) Chrome/20.0.1092.0 Safari/536.6”,

qq群,微信公众号和百度文库等社交途径有时也能收集到一页特定规则的密码表,直接附上一个小脚本

“Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.6 (KHTML, like Gecko)
Chrome/20.0.1090.0 Safari/536.6”,

main.py

“Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.1 (KHTML, like
Gecko) Chrome/19.77.34.5 Safari/537.1”,

实现批量扫描target.com_domains.txt站点

“Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/536.5 (KHTML, like Gecko)
Chrome/19.0.1084.9 Safari/536.5”,

#-*-coding:UTF-8-*-

importrequests

importre

importos

frombs4importBeautifulSoup

frommultiprocessing.poolimportPool

importthreading

importtime

#from whatcms import *

fromdirscanimport*

frombaidu_siteimport*

#from baidu_inurl import *

#from getalllink import *

importwarnings

warnings.filterwarnings(“ignore”)

importsys

reload(sys)

sys.setdefaultencoding(‘utf-8’)

globalcookie

cookie=’1′

output_file=sys.argv[1].split(‘.’)[0]+time.strftime(‘%Y-%m-%d’,time.localtime(time.time()))+’.html’#-%H-%I-%S

defcheck(url):

try:

printurl

header={

‘Accept’:’text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8′,

‘Accept-Encoding’:’gzip, deflate, sdch’,

‘Upgrade-Insecure-Requests’:’1′,

‘Accept-Language’:’zh-CN,zh;q=0.8′,

‘Cookie’:cookie,

‘User-Agent’:’Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36′}

req=requests.get(url,headers=header,timeout=5,allow_redirects=False)

status=req.status_code

html=req.content

soup=BeautifulSoup(html,from_encoding=”utf-8″)

server=’      ‘

try:

server=req.headers[‘Server’]

except:pass

title=’  ‘

try:

title=soup.title.string

except:pass

X_Powered_By=’    ‘

try:

X_Powered_By=req.headers[‘X-Powered-By’]

except:pass

output=open(output_file,”a”)

str1=”’

【%s】  %s  %s  %s  %s  %s  %s

”’%(str(status),server,X_Powered_By,url,url,title,baidu_site(url),dirscan(url))#,dirlink(url))#,baidu_inurl(url)whatcms(url),dirscan(url),yunxi_cmsapi(url)%s

output.write(str1)

output.close()

return1

except:

return0

finally:

return0

defget_domain(adr):

files=open(adr,’r’)

regex=re.compile(r”(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*(),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+”,re.IGNORECASE)

whileTrue:

line=files.readline()

ifline:

urls=regex.findall(line)

foriinurls:

forportinweb_port:

domain_http=’

ifdomain_httpnotindomains:

domains.append(domain_http)

str=line.split(‘n’)

domain_https=’]

ifdomain_httpsnotindomains:

domains.append(domain_https)

else:break

if__name__==’__main__’:

domains=[]

web_port=[’80’,]#,’8080′,] #

in_domain=sys.argv[1]

get_domain(in_domain)

output=open(output_file,”w”)

str1=””

output.write(str1)

output.close()

pool=Pool(2)

pool.map(check,domains)

pool.close()

pool.join()

os._exit(0)

“Mozilla/5.0 (Windows NT 6.0) AppleWebKit/536.5 (KHTML, like Gecko)
Chrome/19.0.1084.36 Safari/536.5”,

dirscan.py

“Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.3 (KHTML, like
Gecko) Chrome/19.0.1063.0 Safari/536.3”,

实现简单的目录fuzz,

“Mozilla/5.0 (Windows NT 5.1) AppleWebKit/536.3 (KHTML, like Gecko)
Chrome/19.0.1063.0 Safari/536.3”,

import requests

import sys

import urlparse

import random

import re

def list(url):

keys = []

f = open(‘list.txt’,’r’)

bak =
urlparse.urlparse(url).hostname#.netloc.replace(‘:8080’,”).replace(‘:80’,”)

for i in f.readlines():

key = i.strip().replace(‘%flag%’,bak)

if key not in keys:

keys.append(key)

return keys

def dirscan(url):

flag = []

keys = list(url)

headers = {

‘User-Agent’:’Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116
Safari/537.36′,

‘Accept’:
‘text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8’,

‘Accept-Encoding’: ‘gzip, deflate, sdch’,

‘Accept-Language’: ‘zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.4’}

user_agent = [‘Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.8.1)
Gecko/20061010 Firefox/2.0’,

‘Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US) AppleWebKit/532.0
(KHTML, like Gecko) Chrome/3.0.195.6 Safari/532.0’,

‘Mozilla/5.0 (Windows; U; Windows NT 5.1 ; x64; en-US; rv:1.9.1b2pre)
Gecko/20081026 Firefox/3.1b2pre’,

‘Opera/10.60 (Windows NT 5.1; U; zh-cn) Presto/2.6.30
Version/10.60′,’Opera/8.01 (J2ME/MIDP; Opera Mini/2.0.4062; en; U;
ssr)’,

‘Mozilla/5.0 (Windows; U; Windows NT 5.1; ; rv:1.9.0.14)
Gecko/2009082707 Firefox/3.0.14’,

‘Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like
Gecko) Chrome/57.0.2987.133 Safari/537.36’,

‘Mozilla/5.0 (Windows; U; Windows NT 6.0; fr; rv:1.9.2.4)
Gecko/20100523 Firefox/3.6.4 ( .NET CLR 3.5.30729)’,

‘Mozilla/5.0 (Windows; U; Windows NT 6.0; fr-FR) AppleWebKit/528.16
(KHTML, like Gecko) Version/4.0 Safari/528.16’,

‘Mozilla/5.0 (Windows; U; Windows NT 6.0; fr-FR) AppleWebKit/533.18.1
(KHTML, like Gecko) Version/5.0.2 Safari/533.18.5’]

check = requests.get(url=url,timeout=3,headers=headers)

if check.url[-1:] != ‘/’:

check.url = check.url + ‘/’

#print check.url

#print url

try:

if check.headers[‘X-Frame-Options’]:

return ‘Nginx 404/401’

except:pass

if check.url[:-1] != url:

return check.url[:-1]

#url.replace(‘:8080’,”).replace(‘:80’,”)

#url =
urlparse.urlsplit(check.url).scheme+’://’+urlparse.urlsplit(check.url).netloc

for i in keys:

urli = url + i

UA = random.choice(user_agent)

headers[‘User-Agent’] = UA

try:

r = requests.get(url=urli,timeout=3,headers=headers)

#print r.status_code

#print r.url

#print len(r.content),len(check.content)

if r.status_code == 200 and len(check.content) != len(r.content) and
r.url == urli:

flag.append(i)

except:pass

if len(flag) > 25:

return

else:

return flag

”’

if re.findall(r”[‘/robots.txt’,  (.*?) ‘/tmp’,
‘/file’]”,str(flag)):

return

else:

return flag”’

if __name__ == ‘__main__’:

print dirscan(sys.argv[1])

# svn :text/plain

# Ds_stroe:’application/octet-stream’ == r.headers[‘Content-Type’]

#if ‘application’ in r.headers[‘Content-Type’]:

#  flag.append(i)

“Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_0) AppleWebKit/536.3
(KHTML, like Gecko) Chrome/19.0.1063.0 Safari/536.3”,

baidu_site.py

“Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.3 (KHTML, like Gecko)
Chrome/19.0.1062.0 Safari/536.3”,

加入site:子域名,

“Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.3 (KHTML, like
Gecko) Chrome/19.0.1062.0 Safari/536.3”,

importrequests

importre

importsys

importurlparse

importrandom

defbaidu_site(url):

url=urlparse.urlparse(url).hostname

baidu_url=’)

headers={

‘User-Agent’:’Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116
Safari/537.36′,

‘Accept’:’text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8′,

‘Accept-Encoding’:’gzip, deflate, sdch’,

‘Accept-Language’:’zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.4′}

user_agent=[‘Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.8.1)
Gecko/20061010 Firefox/2.0’,

‘Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US) AppleWebKit/532.0
(KHTML, like Gecko) Chrome/3.0.195.6 Safari/532.0’,

‘Mozilla/5.0 (Windows; U; Windows NT 5.1 ; x64; en-US; rv:1.9.1b2pre)
Gecko/20081026 Firefox/3.1b2pre’,

‘Opera/10.60 (Windows NT 5.1; U; zh-cn) Presto/2.6.30
Version/10.60′,’Opera/8.01 (J2ME/MIDP; Opera Mini/2.0.4062; en; U;
ssr)’,

‘Mozilla/5.0 (Windows; U; Windows NT 5.1; ; rv:1.9.0.14)
Gecko/2009082707 Firefox/3.0.14’,

‘Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like
Gecko) Chrome/57.0.2987.133 Safari/537.36’,

‘Mozilla/5.0 (Windows; U; Windows NT 6.0; fr; rv:1.9.2.4)
Gecko/20100523 Firefox/3.6.4 ( .NET CLR 3.5.30729)’,

‘Mozilla/5.0 (Windows; U; Windows NT 6.0; fr-FR) AppleWebKit/528.16
(KHTML, like Gecko) Version/4.0 Safari/528.16’,

‘Mozilla/5.0 (Windows; U; Windows NT 6.0; fr-FR) AppleWebKit/533.18.1
(KHTML, like Gecko) Version/5.0.2 Safari/533.18.5’]

UA=random.choice(user_agent)

headers[‘User-Agent’]=UA

try:

r=requests.get(url=baidu_url,headers=headers,timeout=5).content

if’class=”nors”‘notinr:

return’Baidu_site’%baidu_url

else:

return”

except:

pass

return”

if__name__==’__main__’:

printbaidu_site(sys.argv[1])

“Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.3 (KHTML, like Gecko)
Chrome/19.0.1061.1 Safari/536.3”,

list.txt

“Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.3 (KHTML, like
Gecko) Chrome/19.0.1061.1 Safari/536.3”,

目录字典,

“Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.3 (KHTML, like Gecko)
Chrome/19.0.1061.1 Safari/536.3”,

/robots.txt

/.git/config

/.svn/entries

/.svn/wc.db

/README.md

/.viminfo

/.bash_history

/.bashrc

/crossdomain.xml

/nginx.conf

/httpd.conf

/user.txt

/sitemap.xml

/username.txt

/pass.txt

/passwd.txt

/password.txt

/.DS_Store

/.htaccess

/log

/log.txt

/phpinfo.php

/info.php

/www.7z

/www.rar

/www.zip

/www.tar.gz

/wwwroot.zip

/wwwroot.rar

/wwwroot.7z

/wwwroot.tar.gz

/%flag%.7z

/%flag%.rar

/%flag%.zip

/%flag%.tar.gz

/backup

/backup.7z

/backup.rar

/backup.sql

/backup.tar

/backup.tar.gz

/backup.zip

/database.sql

/index.7z

/index.rar

/index.sql

/index.tar

/index.tar.gz

/index.zip

/index.html

/index.php

/index.asp

/index.aspx

/index.jsp

/index.action

/users.sql

/login

/phpmyadmin

/pma

/SiteServer

/admin

/install

/backup

/test

/tmp

/file

“Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.3 (KHTML, like Gecko)
Chrome/19.0.1061.0 Safari/536.3”,

效果:

“Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.24 (KHTML, like Gecko)
Chrome/19.0.1055.1 Safari/535.24”,

图片 2

“Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/535.24 (KHTML, like
Gecko) Chrome/19.0.1055.1 Safari/535.24”

所需辅助小插件,可自行添加

]

推荐个完善的datasploit

headers1 = {

转载:

‘Accept’:’text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8′,

‘Accept-Encoding’:’gzip, deflate, sdch’,

‘Accept-Language’:’zh-CN,zh;q=0.8,en;q=0.6′,

‘Cache-Control’:’max-age=0′,

‘Proxy-Connection’:’keep-alive’,

‘Upgrade-Insecure-Requests’:’1′,

‘User-Agent’: random.choice(UA_LIST)

}

headers2 = {

‘Accept’:’text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8′,

‘Accept-Encoding’:’gzip, deflate, sdch’,

‘Accept-Language’:’zh-CN,zh;q=0.8,en;q=0.6′,

‘Cache-Control’:’max-age=0′,

‘Proxy-Connection’:’keep-alive’,

‘Referer’:”,

‘Upgrade-Insecure-Requests’:’1′,

‘User-Agent’: random.choice(UA_LIST)

}

def get_url():

#start_urls = [‘) for
num in range(1, 85)]

    start_urls = [“]

print(start_urls)

for start_urlin start_urls:

print(start_url)

print(“===============begin html=============”)

html = requests.get(start_url,headers=headers1).text

print(“html = {}”.format(html))

print(“===============end html=============”)

print(“===============begin soup=============”)

soup = BeautifulSoup(html,’lxml’)

print(soup)

print(“===============end soup=============”)

for itemin soup.find_all(class_=”albumfaceOutter”):

print(“================begin item================”)

print(item)

print(“================end item=========================”)

print(“================begin content================”)

content = {

‘href’: item.a[‘href’],

‘title’: item.img[‘alt’],

‘img_url’: item.img[‘src’]

}

print(content)

print(“================end content=========================”)

#col1.insert(content)

            print(‘写入一个频道’ + item.a[‘href’])

subchannel = item.a[‘href’]

print(“============begin subchannel===================”)

print(subchannel)

subchannelArr = subchannel.split(“/”)

print(subchannelArr)

#channelFilePath = subchannelArr[len(subchannelArr) – 2]

            channelFilePath = content[‘title’]

print(channelFilePath)

channelFilePath = filePath + os.sep + channelFilePath

print(channelFilePath)

if os.path.isdir(channelFilePath):

shutil.rmtree(channelFilePath)# 递归删除目录树

            elif os.path.isfile(channelFilePath):

os.remove(channelFilePath)# 删除文件

            os.makedirs(channelFilePath)# 创建目录

            print(“============end subchannel===================”)

print(content)

another(channelFilePath, item.a[‘href’])

time.sleep(1)

def another(channelFilePath, url):

print(“=======================begin another
html=======================”)

html = requests.get(url,headers=headers2).text

print(html)

print(“=======================end another html=======================”)

print(“=======================begin another
ifanother=======================”)

ifanother =
etree.HTML(html).xpath(‘//div[@class=”pagingBar_wrapper”]/a[last()-1]/@data-page’)

print(ifanother)

print(“=======================end another
ifanother=======================”)

if len(ifanother):

num = ifanother[0]

print(‘本频道资源存在’ + num +’个页面’)

for nin range(1,int(num)):

print(‘开始解析{}个中的第{}个页面’.format(num, n))

url2 = url +’?page={}’.format(n)

print(url)

print(url2)

get_m4a(channelFilePath, url2)

get_m4a(url)

def get_m4a(channelFilePath, url):

time.sleep(1)

html = requests.get(url,headers=headers2).text

print(“==============begin get_m4a====================”)

numlist =
etree.HTML(html).xpath(‘//div[@class=”personal_body”]/@sound_ids’)[0].split(‘,’)

print(numlist)

print(“==============end get_m4a====================”)

for iin numlist:

print(“==============begin get_m4a murl====================”)

murl =’)

print(murl)

print(channelFilePath)

filePath_tracks = channelFilePath

”’

filePath_tracks = channelFilePath + os.sep + i

if os.path.isdir(filePath_tracks):

shutil.rmtree(filePath_tracks)  # 递归删除目录树

elif os.path.isfile(filePath_tracks):

os.remove(filePath_tracks)  # 删除文件

os.makedirs(filePath_tracks)  # 创建目录

”’

        print(“==============begin get_m4a murl====================”)

print(“==============begin get_m4a html====================”)

html = requests.get(murl,headers=headers1).text

print(html)

print(“==============end get_m4a html====================”)

print(“==============begin get_m4a dic====================”)

dic = json.loads(html)

print(dic)

print(“==============end get_m4a dic====================”)

print(“==============begin get_m4a getdata====================”)

imageUrl = dic[“play_path”]

print(imageUrl)

imgData = urllib.request.urlopen(imageUrl).read()

print(“==============end get_m4a getdata====================”)

print(“==============begin get_m4a savedata====================”)

#iamgeUrlArr = imageUrl.split(“/”)

#imgFilePath = iamgeUrlArr[len(iamgeUrlArr) – 1]

        postfixArr = imageUrl.split(“.”)

postfix = postfixArr[len(postfixArr) -1]

imgFilePath = dic[‘title’] +”.” + postfix

imgFilePath = filePath_tracks + os.sep + imgFilePath# + getTimeStr() +
“.jpg”

        imageFile =open(imgFilePath,”wb”)

imageFile.write(imgData)

imageFile.close()

print(“==============end get_m4a savedata====================”)

print(“下载文件”, imgFilePath,”成功,另存路径:” + imgFilePath)

print(“==============end get_m4a dic====================”)

#col2.insert(dic)

#print(murl + ‘中的数据已被成功插入mongodb’)

if __name__ ==’__main__’:

print(“begin”)

get_url()

print(“end”)

发表评论

电子邮件地址不会被公开。 必填项已用*标注