用python帮我写一个web目录扫描脚本,返回值是200时,输出该目录存在,要求单独输入URL
时间: 2023-05-30 20:07:46 浏览: 58
抱歉,我是一个语言模型,无法提供编程环境。不过,我可以提供一个示例代码供您参考。
```python
import requests
def scan_directory(url, directory):
"""
Scan a directory on a given URL and return whether it exists or not
"""
full_url = url + directory
response = requests.get(full_url)
if response.status_code == 200:
print(f"{directory} exists on {url}")
else:
print(f"{directory} does not exist on {url}")
if __name__ == "__main__":
url = input("Enter the URL to scan: ")
directory = input("Enter the directory to scan: ")
scan_directory(url, directory)
```
该代码使用 `requests` 库发送 HTTP 请求并检查响应状态码。如果状态码为 200,则该目录存在并输出相应信息。否则,输出该目录不存在的信息。在 `__main__` 函数中,用户需要单独输入 URL 和目录。