对于我的课程,我必须建立一个网络刮板,它可以浏览img,word文档和pdf的网站并将它们下载到一个文件中,我有img的下载工作,但当我将代码改为下载docs或pdf时,它根本找不到任何东西,我使用beautifulsoup来刮网站,我知道网站上有些文档和pdf文件无法下载。
from bs4 import BeautifulSoup
import urllib.request
import shutil
import requests
from urllib.parse import urljoin
import sys
import time
import os
import url
import hashlib
import re
url = 'http://www.soc.napier.ac.uk/~40009856/CW/'
path=('c:\\temp\\')
def ensure_dir(path):
directory = os.path.dirname(path)
if not os.path.exists(path):
os.makedirs(directory)
return path
os.chdir(ensure_dir(path))
def webget(url):
response = requests.get(url)
html = response.content
return html
def get_docs(url):
soup = make_soup(url)
docutments = [docs for d