宝贝回家python爬虫
时间: 2024-01-01 17:23:45 浏览: 28
宝贝回家是一个基于Python的爬虫项目,用于从宝贝回家网站上获取失踪儿童的信息。以下是一个简单的示例代码,演示如何使用Python爬虫来获取宝贝回家网站上的失踪儿童信息:
```python
import requests
from bs4 import BeautifulSoup
# 发送请求获取网页内容
url = 'https://www.baobeihuijia.com/'
response = requests.get(url)
html = response.text
# 使用BeautifulSoup解析网页内容
soup = BeautifulSoup(html, 'html.parser')
# 获取失踪儿童信息
children = soup.find_all('div', class_='child-info')
for child in children:
name = child.find('div', class_='child-name').text
age = child.find('div', class_='child-age').text
gender = child.find('div', class_='child-gender').text
print(f"姓名:{name},年龄:{age},性别:{gender}")
```
这段代码使用了requests库发送HTTP请求,获取宝贝回家网站的内容。然后使用BeautifulSoup库解析网页内容,通过查找特定的HTML元素,获取失踪儿童的姓名、年龄和性别信息,并打印出来。