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

from fake_useragent import UserAgent
import ssl
import requests
from lxml import etree

from time import sleep

def get_html(url):
    '''
    :param url: 要爬取的地址
    :return: 返回html
    '''
    headers = {"User_Agent": UserAgent().random}
    resp = requests.get(url,headers=headers)

    #status_code   返回状态码
    if resp.status_code == 200:
        resp.encoding='utf-8'
        return resp.text
    else:
        return None

def parse_list(html):
    '''
    :param html: 传递进来有一个电影列表的的html
    :return: 返回一个电影的url
    '''

    e = etree.HTML(html)
    # 解决验证CA
    # ssl._create_default_https_context = ssl._create_unverified_context
    list_url = ['https://www.qidian.com{}'.format(url)for url in e.xpath('//div[@class="book-img-box"]/a/@href')]
    return list_url

def parse_index(html):
    '''
    :param html: 传递一个有电影信息的html
    :return: 已经提取好的电影信息
    '''
    e = etree.HTML(html)
    name = e.xpath('//div/h1/span/a/text()')
    return name

def main():
    num = int(input("请输入要获取多少页:"))
    for page in range(num):
        url = 'https://www.qidian.com/all?&page={}'.format(page+1)
        list_html = get_html(url)
        list_url = parse_list(list_html)
        for url in list_url:
            info_html = get_html(url)
            move = parse_index(info_html)
            print(move)

if __name__ == '__main__':
    main()



老师,您帮我看一下,为什么我这个最后返回的是空列表啊,我debug看了一下是这个出问题了。返回了空值,但是我使用插件看了看没问题啊

name = e.xpath('//div/h1/span/a/text()')


Python 全系列/第十五阶段:Python 爬虫开发/爬虫反反爬- 23103楼
Python 全系列/第三阶段:Python 网络与并发编程/并发编程 23104楼
JAVA 全系列/第十三阶段:分布式文件存储与数据缓存/MongoDB 23106楼
Python 全系列/第一阶段:Python入门/面向对象 23108楼
Python 全系列/第一阶段:Python入门/面向对象 23109楼
JAVA 全系列/第六阶段:项目管理与SSM框架/SpringMVC 23110楼
JAVA 全系列/第十三阶段:分布式文件存储与数据缓存/Nginx 23111楼
Python 全系列/第四阶段:函数式编程和核心特性/生成器和装饰器 23112楼
Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 23113楼

老师,帮忙看一下这个报错

"C:\Program Files\Java\jdk-16\bin\java.exe" -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always -javaagent:D:\Toolbox\apps\IDEA-U\ch-0\203.7148.57\lib\idea_rt.jar=62520:D:\Toolbox\apps\IDEA-U\ch-0\203.7148.57\bin -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true -Dfile.encoding=GBK -classpath D:\Java_Code\SpringbootMybatis\target\classes;C:\Users\Mr.G\.m2\repository\org\springframework\boot\spring-boot-starter-thymeleaf\2.4.4\spring-boot-starter-thymeleaf-2.4.4.jar;C:\Users\Mr.G\.m2\repository\org\springframework\boot\spring-boot-starter\2.4.4\spring-boot-starter-2.4.4.jar;C:\Users\Mr.G\.m2\repository\org\springframework\boot\spring-boot\2.4.4\spring-boot-2.4.4.jar;C:\Users\Mr.G\.m2\repository\org\springframework\boot\spring-boot-autoconfigure\2.4.4\spring-boot-autoconfigure-2.4.4.jar;C:\Users\Mr.G\.m2\repository\org\springframework\boot\spring-boot-starter-logging\2.4.4\spring-boot-starter-logging-2.4.4.jar;C:\Users\Mr.G\.m2\repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;C:\Users\Mr.G\.m2\repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar;C:\Users\Mr.G\.m2\repository\org\apache\logging\log4j\log4j-to-slf4j\2.13.3\log4j-to-slf4j-2.13.3.jar;C:\Users\Mr.G\.m2\repository\org\apache\logging\log4j\log4j-api\2.13.3\log4j-api-2.13.3.jar;C:\Users\Mr.G\.m2\repository\org\slf4j\jul-to-slf4j\1.7.30\jul-to-slf4j-1.7.30.jar;C:\Users\Mr.G\.m2\repository\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;C:\Users\Mr.G\.m2\repository\org\yaml\snakeyaml\1.27\snakeyaml-1.27.jar;C:\Users\Mr.G\.m2\repository\org\thymeleaf\thymeleaf-spring5\3.0.12.RELEASE\thymeleaf-spring5-3.0.12.RELEASE.jar;C:\Users\Mr.G\.m2\repository\org\thymeleaf\thymeleaf\3.0.12.RELEASE\thymeleaf-3.0.12.RELEASE.jar;C:\Users\Mr.G\.m2\repository\org\attoparser\attoparser\2.0.5.RELEASE\attoparser-2.0.5.RELEASE.jar;C:\Users\Mr.G\.m2\repository\org\unbescape\unbescape\1.1.6.RELEASE\unbescape-1.1.6.RELEASE.jar;C:\Users\Mr.G\.m2\repository\org\slf4j\slf4j-api\1.7.30\slf4j-api-1.7.30.jar;C:\Users\Mr.G\.m2\repository\org\thymeleaf\extras\thymeleaf-extras-java8time\3.0.4.RELEASE\thymeleaf-extras-java8time-3.0.4.RELEASE.jar;C:\Users\Mr.G\.m2\repository\org\springframework\boot\spring-boot-starter-web\2.4.4\spring-boot-starter-web-2.4.4.jar;C:\Users\Mr.G\.m2\repository\org\springframework\boot\spring-boot-starter-json\2.4.4\spring-boot-starter-json-2.4.4.jar;C:\Users\Mr.G\.m2\repository\com\fasterxml\jackson\core\jackson-databind\2.11.4\jackson-databind-2.11.4.jar;C:\Users\Mr.G\.m2\repository\com\fasterxml\jackson\core\jackson-annotations\2.11.4\jackson-annotations-2.11.4.jar;C:\Users\Mr.G\.m2\repository\com\fasterxml\jackson\core\jackson-core\2.11.4\jackson-core-2.11.4.jar;C:\Users\Mr.G\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.11.4\jackson-datatype-jdk8-2.11.4.jar;C:\Users\Mr.G\.m2\repository\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.11.4\jackson-datatype-jsr310-2.11.4.jar;C:\Users\Mr.G\.m2\repository\com\fasterxml\jackson\module\jackson-module-parameter-names\2.11.4\jackson-module-parameter-names-2.11.4.jar;C:\Users\Mr.G\.m2\repository\org\springframework\boot\spring-boot-starter-tomcat\2.4.4\spring-boot-starter-tomcat-2.4.4.jar;C:\Users\Mr.G\.m2\repository\org\apache\tomcat\embed\tomcat-embed-core\9.0.44\tomcat-embed-core-9.0.44.jar;C:\Users\Mr.G\.m2\repository\org\glassfish\jakarta.el\3.0.3\jakarta.el-3.0.3.jar;C:\Users\Mr.G\.m2\repository\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.44\tomcat-embed-websocket-9.0.44.jar;C:\Users\Mr.G\.m2\repository\org\springframework\spring-web\5.3.5\spring-web-5.3.5.jar;C:\Users\Mr.G\.m2\repository\org\springframework\spring-beans\5.3.5\spring-beans-5.3.5.jar;C:\Users\Mr.G\.m2\repository\org\springframework\spring-webmvc\5.3.5\spring-webmvc-5.3.5.jar;C:\Users\Mr.G\.m2\repository\org\springframework\spring-aop\5.3.5\spring-aop-5.3.5.jar;C:\Users\Mr.G\.m2\repository\org\springframework\spring-context\5.3.5\spring-context-5.3.5.jar;C:\Users\Mr.G\.m2\repository\org\springframework\spring-expression\5.3.5\spring-expression-5.3.5.jar;C:\Users\Mr.G\.m2\repository\org\mybatis\spring\boot\mybatis-spring-boot-starter\2.1.4\mybatis-spring-boot-starter-2.1.4.jar;C:\Users\Mr.G\.m2\repository\org\springframework\boot\spring-boot-starter-jdbc\2.4.4\spring-boot-starter-jdbc-2.4.4.jar;C:\Users\Mr.G\.m2\repository\com\zaxxer\HikariCP\3.4.5\HikariCP-3.4.5.jar;C:\Users\Mr.G\.m2\repository\org\springframework\spring-jdbc\5.3.5\spring-jdbc-5.3.5.jar;C:\Users\Mr.G\.m2\repository\org\springframework\spring-tx\5.3.5\spring-tx-5.3.5.jar;C:\Users\Mr.G\.m2\repository\org\mybatis\spring\boot\mybatis-spring-boot-autoconfigure\2.1.4\mybatis-spring-boot-autoconfigure-2.1.4.jar;C:\Users\Mr.G\.m2\repository\org\mybatis\mybatis\3.5.6\mybatis-3.5.6.jar;C:\Users\Mr.G\.m2\repository\org\mybatis\mybatis-spring\2.0.6\mybatis-spring-2.0.6.jar;C:\Users\Mr.G\.m2\repository\mysql\mysql-connector-java\5.1.38\mysql-connector-java-5.1.38.jar;C:\Users\Mr.G\.m2\repository\com\alibaba\druid\1.1.12\druid-1.1.12.jar;C:\Users\Mr.G\.m2\repository\org\springframework\spring-core\5.3.5\spring-core-5.3.5.jar;C:\Users\Mr.G\.m2\repository\org\springframework\spring-jcl\5.3.5\spring-jcl-5.3.5.jar com.bjsxt.springbootmybatis.SpringbootmybatisApplication
Java HotSpot(TM) 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.4.4)

2021-04-01 14:37:40.509  INFO 13944 --- [           main] c.b.s.SpringbootmybatisApplication       : Starting SpringbootmybatisApplication using Java 16 on LAPTOP-SSNOOCN5 with PID 13944 (D:\Java_Code\SpringbootMybatis\target\classes started by Mr.G in D:\java_code)
2021-04-01 14:37:40.512  INFO 13944 --- [           main] c.b.s.SpringbootmybatisApplication       : No active profile set, falling back to default profiles: default
2021-04-01 14:37:40.933  WARN 13944 --- [           main] o.m.s.mapper.ClassPathMapperScanner      : No MyBatis mapper was found in '[com.bjsxt.springbootmybatis.mapper]' package. Please check your configuration.
2021-04-01 14:37:41.152  INFO 13944 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2021-04-01 14:37:41.157  INFO 13944 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-04-01 14:37:41.158  INFO 13944 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.44]
2021-04-01 14:37:41.230  INFO 13944 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-04-01 14:37:41.230  INFO 13944 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 674 ms
2021-04-01 14:37:41.260  WARN 13944 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'usersController': Unsatisfied dependency expressed through field 'usersService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userServiceImpl': Unsatisfied dependency expressed through field 'usersMapper'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.bjsxt.mapper.UsersMapper' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
2021-04-01 14:37:41.261  INFO 13944 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2021-04-01 14:37:41.269  WARN 13944 --- [           main] o.a.c.loader.WebappClassLoaderBase       : The web application [ROOT] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 java.base@16/java.lang.Object.wait(Native Method)
 java.base@16/java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:155)
 app//com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:43)
2021-04-01 14:37:41.274  INFO 13944 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-04-01 14:37:41.286 ERROR 13944 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Field usersMapper in com.bjsxt.springbootmybatis.service.impl.UserServiceImpl required a bean of type 'com.bjsxt.mapper.UsersMapper' that could not be found.

The injection point has the following annotations:
	- @org.springframework.beans.factory.annotation.Autowired(required=true)


Action:

Consider defining a bean of type 'com.bjsxt.mapper.UsersMapper' in your configuration.


Process finished with exit code 1

Java_Code.rar


JAVA 全系列/第九阶段:Spring Boot实战/Spring Boot 23114楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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