Write code to recursively find all the direct urls to the files at…
- User
Write code to recursively find all the direct urls to the files at https://arcjav.arcjavdb.workers.dev/0:/001-050/%E4%B8%8A%E5%8E%9F%E4%BA%9A%E8%A1%A3/
- Assistant
To fetch all direct URLs to the files at the provided link, you can use a combination of Python requests and BeautifulSoup libraries to extract the data. First, you'll need to install these libraries if you haven't already:
pip install requests pip install beautifulsoup4Here's the complete code to recursively fetch direct urls:
import requests from bs4 import BeautifulSoup from urllib.parse import urljoin, urlparse def check_valid_url(url): try: result = urlparse(url) return all([result.scheme, result.netloc]) except ValueError: return False def fetch_direct_urls(url): if not check_valid_url(url): raise ValueError("Invalid URL") response = requests.get(url) if response.status_code == 200: soup = BeautifulSoup(response.content, "html.parser") for link in soup.find_all('a'): href = link.get('href') full_url = urljoin(url, href) if check_valid_url(full_url) and not href.startswith("?"): if full_url.endswith("/"): fetch_direct_urls(full_url) else: print(full_url) if __name__ == "__main__": base_url = "https://arcjav.arcjavdb.workers.dev/0:/001-050/%E4%B8%8A%E5%8E%9F%E4%BA%9A%E8%A1%A3/" fetch_direct_urls(base_url)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.