将目录从列表设为一个目录

时间:2019-03-30 09:44:10

标签: python

我有以下代码:

from bs4 import BeautifulSoup as bs
import os
import re
import requests
import sys
import lxml.html
import requests
from pathlib import Path
url = https://streaming.ine.com/c/comptia-cloud-plus
#url = input("Please enter the url for course: ")
page = requests.get(url)
tree = lxml.html.fromstring(page.content)
names = tree.xpath('//div[@class="course-title"]/text()')
names = filter(lambda n: n.strip(), names)
table = str.maketrans(dict.fromkeys('?:/'))
for index, name in enumerate(names):

os.makedirs('MY - {}'.format(name.strip().translate(table)))

soup = bs(page.content, 'html.parser')
listed = soup.find_all('div', class_="cd-timeline-block")
sys.stdout = open(os.path.join(sys.path[0], "file.txt",), "w")
for i, sth in enumerate(listed):
soup1 = bs(sth.encode().decode('utf-8'))
main_title = soup1.find_all('div', class_="cd-timeline-topic") 
[0].contents[0]
sub_list = soup1.find_all('div', class_="cd-timeline-level")
for j, elem in enumerate(sub_list, start=1):
temp = elem.contents[2].rstrip().strip('\n')
temp = re.sub(r"[^a-zA-Z0-9&]+", ' ', temp)

print("/%s.%s/%s.%s.mp4" % (str(i), main_title, str(j), temp[1:]))

我正在尝试从列表中创建目录,但进入一个主目录:目录名称以“ MY”开头。目录中的数字应从零开始并开始计数。同样在主目录中,我想移动file.txt

谢谢!

0 个答案:

没有答案