让我看看泉州前五的酒店到底是哪五家

import requests
from bs4 import BeautifulSoup
import pandas as pd
url="http://www.mafengwo.cn/search/q.php?q=泉州"  #想爬的网站
headers={'User-Agent':'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36'}
r= requests.get(url,timeout=30,headers=headers)  #发送请求
r.encoding='utf-8'
soup=BeautifulSoup(r.text,'html.parser')  #解析
a=soup.findAll('li',class_='clearfix')   #查找想要爬的内容
for b in a:
    print(b.get_text())   #直接输出结果

  

在网站中F12  并找到想要爬取的信息

使用代码爬取并输出后,原来是这五家酒店

posted @ 2020-03-18 17:19  刚好路过的假面骑士  阅读(182)  评论(0编辑  收藏  举报