

实际情况是这样的,因为用python分析网页非常,比如下载某页中的全部pdf链接
from __future__ import unicode_literals
from bs import BeautifulSoup
import requests
import codecs
r = requests.get('you url')
s = BeautifulSoup(r.text)
links = s.findall('a')
pdfs = []
for link in links:
href = link.get('href')
if href.endswith('.pdf'):
pdfs.append(href)
with open('you file', 'w', 'gb') as f:
for pdf in pdfs:
f.write(pdf + '
')使用python创建多个文件
#coding=utf-8
'''
Created on 2012-5-29
@author: xiaochou
'''
import os
import time
def nsfile(s):
'''The number of new expected documents'''
#判断文件夹是否存在,如果不存在则创建
b = os.path.exists("E:\testFile\")
if b:
print "File Exist!"
else:
os.mkdir("E:\testFile\")
#生成文件
for i in range(1,s+1):
localTime = time.strftime("%Y%m%d%H%M%S",time.localtime())
#print localtime
filename = "E:\testFile\"+localTime+".txt"
#a:以追加模式打开(必要时可以创建)append;b:表示二进制
f = open(filename,'ab')
testnote = '测试文件'
f.write(testnote)
f.close()
#以上内容是小编给大家分享的Python批量创建迅雷任务及创建多个文件的实例代码,希望对大家有所帮助。
