'''03_糗事百科案例.py''' import requests from lxml import etree import pymongo class QiuShiSpider: def init(self): self.url = "https://www.qiushibaike.com/8hr/page/1/" self.headers = {"User-Agent":"Mozilla/5.0"} self.conn = pymongo.MongoClient("localhost",27017) self.db = self.conn.Baikedb self.myset = self.db.baikeset def getPage(self): res = requests.get(self.url,headers=self.headers) res.encoding = "utf-8" html = etree.HTML(res.text)