使用python爬取大众点评深圳火锅前十
时间: 2023-09-17 09:10:02 浏览: 117
好的,我可以帮您回答这个问题。为了爬取大众点评深圳火锅前十,您需要使用Python爬虫技术,以下是一个简单的爬虫示例代码:
```python
import requests
from bs4 import BeautifulSoup
url = "https://www.dianping.com/shenzhen/ch10/g110"
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')
hotpot_list = soup.select('.shop-list li')
for hotpot in hotpot_list:
name = hotpot.select('.tit a')[0].get_text().strip()
score = hotpot.select('.comment span')[0].get_text().strip()
address = hotpot.select('.tag-addr a')[0].get_text().strip()
print(name, score, address)
```
以上代码会从大众点评深圳火锅页面爬取前十家火锅店的名称、评分和地址,并将结果打印出来。您可以根据需要修改代码以获取更多信息。
阅读全文