会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132474个问题

1.报错

com.fasterxml.jackson.databind.exc.InvalidTypeIdException: Missing type id when trying to resolve subtype of [simple type, class org.springframework.session.data.mongo.MongoSession]: missing type id property '@class'

 at [Source: (String)"{"_id": "43386047-6d40-40fa-84e9-01b01ee00df5", "created": {"$date": "2021-05-15T13:44:27.095Z"}, "accessed": {"$date": "2021-05-15T13:44:27.096Z"}, "interval": "PT30M", "principal": null, "expireAt": {"$date": "2021-05-15T14:14:27.096Z"}, "attr": {"$binary": {"base64": "rO0ABXNyABFqYXZhLnV0aWwuSGFzaE1hcAUH2sHDFmDRAwACRgAKbG9hZEZhY3RvckkACXRocmVzaG9sZHhwP0AAAAAAAAB3CAAAABAAAAAAeA==", "subType": "00"}}}"; line: 1, column: 405]

image.png

image.png

session_mongodb.rar



2.运行老师的源码也报错:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.

2021-05-15 22:01:11.579 ERROR 15992 --- [           main] o.s.boot.SpringApplication               : Application run failed


org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat


JAVA 全系列/第十五阶段:Spring Session会话管理/Spring Session MongoDB 21467楼
Python 全系列/第一阶段:Python入门/控制语句 21468楼
JAVA 全系列/第五阶段:JavaWeb开发/Servlet技术详解(旧) 21471楼

from threading import Thread
import requests
from lxml import etree
from fake_useragent import UserAgent
from queue import Queue    #引入一个队列,传输url


class Spider(Thread):
    def __init__(self, url_queue):
        Thread.__init__(self)
        self.url_queue = url_queue

    def run(self):
        while not self.url_queue.empty():
            url = self.url_queue.get()
            print(url)
            headers = {'User-Agent': UserAgent().chrome}
            resp = requests.get(url, headers=headers)
            e = etree.HTML(resp.text)
            dates = [div.xpath('string(.)').strip() for div in e.xpath('//div[@class="th200"]/text()')]  #如果这里这样写会报错:
            Maxtemps =e.xpath('//div[@class="th140"][1]/text()')   #如果这样写,取的数据不是base_url中的数据。
            Mintemps =e.xpath('//div[@class="th140"][2]/text()')
            Weathers =e.xpath('//div[@class="th140"][3]/text()')
            Windirs = e.xpath('//div[@class="th140"][4]/text()')
            for date, Maxtemp, Mintemp, Weather, Windir in zip(dates, Maxtemps, Mintemps, Weathers, Windirs):
                contents=[date, Maxtemp, Mintemp, Weather, Windir]
            with open('qixiang.txt', 'a', encoding='utf-8')as f:  # 'a'是追加的意思,文档打开放在文档写的前面。只打开一次。
                for content in contents:
                    f.write(content + '\t''\t''\t''\n')          # 问题:1.这里并没有追加新的内容,而是把当前页面重复加入;2.效果应该是打印某年某一个月全部数据:一行,字段之间有空格,每行换行。


if __name__ == '__main__':
    base_url = 'http://lishi.tianqi.com/zhengzhou/2011{}.html/'
    url_queue = Queue()
    for num in range(1, 13):
        if num <10:
           url_queue.put(base_url.format("%02d" % num))
        else:
            url_queue.put(base_url.format(num))

    for num in range(3):
        spider = Spider(url_queue)
        spider.start()

老师:我模仿多线程的程序讲解,爬取http://lishi.tianqi.com/zhengzhou/网站上的气象数据,想选择相应的年,月,爬取对应的数据。程序运行后的问题是:

1.没有爬取指定页面

base_url = 'http://lishi.tianqi.com/zhengzhou/2011{}.html/'

2.没有正确保存数据

没有追加新的内容,而是把当前页面重复加入;2.效果应该是打印某年某一个月全部数据:一行,字段之间有空格,每行换行。

3.取当面页面的数据时,会报错

[div.xpath('string(.)').strip() for div

我已经反复看教学视频,上网查资料,不知道问题在哪里,请老师帮助修改一下代码,谢谢!

Python 全系列/第十五阶段:Python 爬虫开发/爬虫反反爬- 21473楼
JAVA 全系列/第十五阶段:Spring Session会话管理/Spring Session 21474楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/多线程技术(旧) 21475楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637