泉州酒店排名及价格

 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)
soup=BeautifulSoup(r.text,'lxml')
x=[]#建一个列表
for list1 in soup.find_all('li',class_="clearfix"):
    x.append(list1.get_text())   

print (x)

打开网站

点击右键查看源代码

找到要爬取的数据

用代码进行爬取

最终得到:

 

posted @ 2020-03-18 15:56  陈淑娟  阅读(225)  评论(0编辑  收藏  举报