传入爬虫获取的URL地址参数 用于补全URL地址
links = '/ABC/BCD.HTML'
Inspect_url(links)
def Inspect_url(links): # 检查URL地址是否完整
url = 'https://baidu.com' 需改为采集页面的地址的前缀
print(len(links))
if len(links) > 1:
new_links = []
for link in links:
print(link)
# 判断是否为相对地址
if not link.startswith(('http://', 'https://')):
# 补全相对地址
full_url = url + link
new_links.append(full_url)
print(f'补全后的绝对地址: {full_url}')
else:
new_links.append(link)
# 已经是绝对地址,直接打印
print(f'绝对地址: {link}')
return new_links
elif len(links) == 1:
print('等于1')
link = links[0]
if not link.startswith(('http://', 'https://')):
full_url = url + link
print(f'补全后的绝对地址: {full_url}')
return full_url
else:
return links[0]
elif len(links) < 1:
links = '空'
return links