1. 首页
  2. 编程语言
  3. Python
  4. 03-糗事百科案例(Python脚本)

03-糗事百科案例(Python脚本)

上传者: 2023-06-28 20:28:09上传 PY文件 1.83KB 热度 7次

'''

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 = ...
用户评论