# -*- coding: utf-8 -*-
"""
Created on Mon May 7 15:18:17 2018
@author: chens
"""
import urllib.request
from bs4 import BeautifulSoup
import pymysql.cursors
'''
目标:获取酒店名称和酒店星级
'''
url1 = 'http://hotels.ctrip.com/hotel/435383.html'
html1 = urllib.request.urlopen(url1).read().decode('utf-8')
#1.获取酒店名称信息
soup_name = BeautifulSoup(html1,'lxml')
hotelName = soup_name.h2.string
print("酒店名称为:{}".format(hotelName))
#2.获取酒店星级信息
result_star = soup_name.find_all(attrs={"class":"grade"})
#print(result1)
result_star =str(result_star)
soup_star = BeautifulSoup(result_star,'lxml')
result_star = soup_star.find_all('span')
hotelStar = result_star[0]['title']
print("酒店星级为:{}".format(hotelStar))
'''
目标:获取酒店最低房价和评论总数
'''
url2 = "http://m.ctrip.com/html5/hotel
爬取携程信息
最新推荐文章于 2024-06-28 16:12:59 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)