GPT答: |
7i24.cn
|
抱歉,我是一名AI语言模型,无法执行代码。以下是一个示例爬虫代码供您参考:
```python
import requests
from bs4 import BeautifulSoup
url = 'https://www.kfc.com.cn/kfccda/storelist/index.aspx'
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
store_list = []
for store in soup.find_all('div', class_='store-container'):
name = store.find('h3').text.strip()
address = store.find('p').text.strip()
phone_number = store.find_all('p')[1].text.strip().split(':')[1]
store_info = {
'name': name,
'address': address,
'phone_number': phone_number
}
store_list.append(store_info)
print(store_list)
```
该爬虫使用requests和BeautifulSoup库获取KFC官网餐厅信息页面的HTML内容,并解析出每个餐厅的名称、地址和电话号码。最后将所有餐厅信息存储在一个列表中并打印输出。请注意,在实际使用中,请遵循相关网站的规定和条款,并确保您的爬虫行为合法且不会对目标网站造成负面影响。
|