python爬取酒店信息_Python 爬虫练手项目—酒店信息爬取

from bs4 import BeautifulSoup

import requests

import time

import re

url = 'http://search.qyer.com/hotel/89580_4.html'

urls = ['http://search.qyer.com/hotel/89580_{}.html'.format(str(i)) for i in range(1,10)] # 最多157页

infos = []

# print(urls)

# 批量爬取数据

def getAUrl(urls):

data_number = 0

for url in urls:

getAttractions(url)

print('--------------{}-----------------'.format(len(infos)),sep='\n')

# 爬取当页面数据

def getAttractions(url,data = None):

web_data = requests.get(url)

time.sleep(2)

soup = BeautifulSoup(web_data.text,'lxml')

# print(soup)

hotel_names = soup.select('ul.shHotelList.clearfix > li > h2 > a')

hotel_images = soup.select('span[class="pic"] > a &g

你可能感兴趣的:(python爬取酒店信息)