去哪儿网景点评论爬取
时间: 2023-10-11 15:11:30 浏览: 356
您可以使用Python的爬虫库,例如BeautifulSoup和Requests,来爬取去哪儿网的景点评论。以下是一个简单的示例代码:
```python
import requests
from bs4 import BeautifulSoup
def get_comments(url):
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')
comments = soup.find_all('div', class_='comments-item')
for comment in comments:
content = comment.find('span', class_='heightbox').text.strip()
print(content)
print('---------------------')
# 示例URL
url = 'https://piao.qunar.com/ticket/detailLight/sightCommentList.json?sightId=24194&index=1&page=1&pageSize=10'
get_comments(url)
```
阅读全文