【发布时间】:2021-10-27 01:21:33
【问题描述】:
希望使用 beautifulsoup4、python 3 和 requests 库下载 href 链接。
这是我现在拥有的代码,我认为在这种情况下使用正则表达式会很困难,但我不确定是否可以使用 beautifulsoup3 来完成。我必须从网格中下载所有形状文件,并希望自动执行此任务。谢谢!
网址: https://earth-info.nga.mil/index.php?dir=coordsys&action=gars-20x20-dloads
import requests
from bs4 import BeautifulSoup
import re
URL = 'https://earth-info.nga.mil/index.php?dir=coordsys&action=gars-20x20-dloads'
page = requests.get(URL)
soup = BeautifulSoup(page.content,'html.parser')
results = re.findall(r'<a[^>]* href="([^"]*)"', page)
print(results)
【问题讨论】:
标签: python-3.x web-scraping beautifulsoup python-requests