import time
from urllib import parse
import requests
import re
import os
headers ={
‘user-agent’: ‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36’
}
url_ = ‘https://www.vmgirls.com/12945.html’
response = requests.get(url=url_, headers=headers)
html = response.text
dir_name = re.findall(’
(.*?)
’, html)【-1】if not os.path.exists(dir_name):
os.mkdir(dir_name)
print(dir_name)
urls = re.findall(’ ’, html)
for url in urls:
time.sleep(1)
url = parse.urljoin(‘http://www.vmgirls.com/’, url)
print(url)
file_name = url.split(’/’)【-1】
response = requests.get(url=url, headers=headers)
with open(dir_name + ‘/’ + file_name, mode=‘wb’) as f:
f.write(response.content)
print(‘正在保存’, file_name)
我还写了另外一种方法,详细可以访问我的博客https://www.wangxe.top/2020/08/23/vmgirls/