我需要下载https://www.archdaily.cn/这个网站的图片的python代码
时间: 2024-01-01 22:06:38 浏览: 29
可以使用Python的库 BeautifulSoup 和 requests 来实现。以下是一个示例代码:
```
import requests
from bs4 import BeautifulSoup
url = 'https://www.archdaily.cn/'
response = requests.get(url)
html = response.content
soup = BeautifulSoup(html, 'html.parser')
images = soup.find_all('img')
for image in images:
image_url = image['src']
if image_url.endswith('.jpg') or image_url.endswith('.png'):
response = requests.get(image_url)
with open(image_url.split('/')[-1], 'wb') as f:
f.write(response.content)
print(f"下载成功:{image_url}")
```
请注意这仅是一个简单示例,可能需要根据具体的需求进行修改。
相关问题
荷兰阿姆斯特丹Matrix One的外观图片
我找到了一些荷兰阿姆斯特丹Matrix One建筑外观的图片,您可以在以下网站查看:
1. ArchDaily: https://www.archdaily.com/897040/matrix-1-office-building-mpsv
2. Archello: https://archello.com/project/matrix-1
3. Mpsv Architects官网: http://www.mpsv.nl/projects/matrix-1
希望这些网站能够帮助您找到您所需要的荷兰阿姆斯特丹Matrix One建筑的外观图片。
python爬虫建筑师可视化案例
以下是一个Python爬虫建筑师可视化案例:
1. 爬取数据
我们可以使用Python爬虫爬取一些建筑师的信息,例如姓名、国籍和出生年份等。这里我们以ArchDaily网站上的建筑师信息为例:
```python
import requests
from bs4 import BeautifulSoup
url = 'https://www.archdaily.com/tag/famous-architects'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'}
response = requests.get(url, headers=headers)
soup = BeautifulSoup(response.text, 'html.parser')
architects = []
for architect in soup.find_all('div', class_='text-image'):
name = architect.find('h3', class_='title').text
nationality = architect.find('p', class_='subtitle').text
birth_year = architect.find('p', class_='caption').text.split(',')[0]
architects.append({'name': name, 'nationality': nationality, 'birth_year': birth_year})
```
2. 可视化数据
接下来,我们可以使用seaborn库将爬取到的数据可视化出来:
```python
import seaborn as sns
import pandas as pd
df = pd.DataFrame(architects)
df['birth_year'] = df['birth_year'].apply(lambda x: int(x) if x else None)
sns.set_theme(style="ticks")
g = sns.catplot(x="nationality", y="birth_year", data=df, kind="box", height=6, aspect=2)
for ax in g.axes.flat:
ax.set_xticklabels(ax.get_xticklabels(), rotation=45, ha='right')
sns.despine(trim=True)
```
这段代码将建筑师的国籍以箱线图的形式展示出来,箱线图的高度表示建筑师的出生年份。通过这种方式,我们可以更加直观地观察到各个国家建筑师的出生年份分布情况,以及它们之间的差异。