创建爬虫----爬取大众点评数据并存入mongoDB数据库

#爬取大众点评多页数据
from urllib.request import urlopen
from bs4 import BeautifulSoup
import pymongo


client = pymongo.MongoClient('localhost',27017)
dzdp = client['dzdp']
url_list = dzdp['url_list']
item_info = dzdp['item_info']

def get_page_link(page_number):
     for each_number in range(1,page_number):
          full_url="http://www.dianping.com/shop/2341453/review_all_grade?pageno={}".format(each_number)
          html=urlopen(full_url)
          bsObj=BeautifulSoup(html)

          nameList=bsObj.findAll("div",{"class":"J_brief-cont"})
          for name in nameList:
              print(name.get_text())
              url_list.insert_one({'text':name.get_text() })



s=get_page_link(71)
print(s)

创建爬虫----爬取大众点评数据并存入mongoDB数据库_第1张图片

你可能感兴趣的:(python爬虫)