【发布时间】:2021-02-23 08:48:38
【问题描述】:
我一直在抓取这个动态网站,它基本上是一个索引链接。我想将每个文件夹中文件的所有下载链接都下载到最后一个子文件夹。我不知道我应该应用什么机制来做到这一点。
代码:
import time
import lxml
import requests
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
url = 'http://dl.ncsbe.gov.s3.amazonaws.com/index.html?prefix='
options = Options()
options.add_argument('--headless')
options.add_argument('--disable-gpu')
driver = webdriver.Chrome(options=options)
driver.get(url)
time.sleep(5)
page = driver.page_source
driver.quit()
soup = BeautifulSoup(page, 'html.parser')
lists = []
for tags in soup.find_all('a'):
links = tags['href']
lists.append(links)
req = requests.get('https://s3.amazonaws.com/dl.ncsbe.gov?delimiter=/').content #from the network tools in F12
soup = BeautifulSoup(req, 'lxml')
names = []
for common in soup.find_all('prefix')[2:]:
names.append(common.text)
names.sort()
print(names)
我只想获取每个文件夹中每个文件类型的下载链接。
【问题讨论】:
-
试试这个链接here
标签: python amazon-s3 web-scraping data-science