会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132387个问题
Python 全系列/第五阶段:数据库编程/mysql介绍与环境安装 18076楼
JAVA 全系列/第二阶段:JAVA 基础深化和提高/智能电话本项目实战 18077楼

老师,麻烦帮我看一下代码,一直显示错误,debug好多次了。谢谢!

JDBC技术2.zip



数据库

image.png


错误提示

java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'stu_id = 'Smith@hotmail.com'' at line 1
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120)
	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
	at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953)
	at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1092)
	at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1040)
	at com.mysql.cj.jdbc.ClientPreparedStatement.executeLargeUpdate(ClientPreparedStatement.java:1350)
	at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdate(ClientPreparedStatement.java:1025)
	at com.bjsxt.dao.impl.BaseDaoImpl.executeUpdate(BaseDaoImpl.java:29)
	at com.bjsxt.dao.impl.StudentDaoImpl.updateStudent(StudentDaoImpl.java:72)
	at service.impl.StudentServiceImpl.modifyStudents(StudentServiceImpl.java:18)
	at com.bjsxt.test.Test.main(Test.java:15)


JAVA 全系列/第三阶段:数据库编程/JDBC技术(旧) 18079楼
JAVA 全系列/第一阶段:JAVA 快速入门/数组和数据存储 18080楼

# _*_coding=utf-8 _*_
from fake_useragent import UserAgent
import requests
from lxml import etree
from time import sleep

def get_html(url):
    """
    :param url: 要爬取的url
    :return返回html
    """
    headers = {
        "User-Agent": UserAgent().chrome
    }
    resp = requests.get(url, headers=headers)
    sleep(3)
    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)
    list_url = ['https://maoyan.com'+ url for url in e.xpath('//div[@class="movie-item-hover"]/a/@href')]
    return list_url

def parse_index(html):
    """
    :param html: 传递进来一个有电影信息的url
    :return  已经提取好的电影信息
    """
    e = etree.HTML(html)
    names = e.xpath('//h1/text()')[0]
    type = e.xpath('//li[@class="ellipsis"]/a/text()')[0]
    actor = e.xpath('//ul[@class="celebrity-list clearfix"]/li[@class="celebrity actor"]/div/a/text()')
    actors = format_actor(actor)
    return {'name': names, 'type': type, 'actor': actors}

def format_actor(actors):
    actor_set = set()  # 去重
    for actor in actors:
        actor_set.add(actor.strip())
    return actor_set

def main():
    num = int(input('请输入要获取多少页数据'))
    for y in range(num):
        url = 'https://maoyan.com/films?showType=3&offset={}'.format(y*30)
        # print(url)
        list_html = get_html(url)
        list_url = parse_list(list_html)
        for url in list_url:
            # print(url)
            info_html = get_html(url)
            movie = parse_index(info_html)
            print(movie)


if __name__ == '__main__':
    main()

image.png

老师为啥没有数据啊!

Python 全系列/第十五阶段:Python 爬虫开发/爬虫反反爬- 18084楼
JAVA 全系列/第六阶段:项目管理与SSM框架/Mybatis 18085楼
Python 全系列/第三阶段:Python 网络与并发编程/并发编程 18086楼

from urllib.request import Request,build_opener,urlopen
from fake_useragent import UserAgent
from urllib.parse import urlencode
from urllib.request import HTTPCookieProcessor

login_url="https://www.mypianku.net/user/login/"
form_data={
    "user":"18628906572",
    "password":"x..k.d$2000$"
}
headers={
    "User-Agent":UserAgent().random}
req=Request(login_url,headers=headers,data=urlencode(form_data).encode())
opener=build_opener()
resp=opener.open(req)


#---------------------------登录成功--------------------


url="https://www.mypianku.net/user/account/"

headers={
    "User-Agent":UserAgent().random,
    "Cookie":"_pk_id.1.f469=6d7b76987328fd10.1626832666.; d_c=d_1412928085; vrg_sc=4bb1ca6010ff37986d716442a23afa73; vrg_go=1; pyad=2; player123=%E6%B2%90%E6%B5%B4%E4%B9%8B%E7%8E%8BHD%23%23%2Fpy%2FlNmZxwmZsBTZ_1.html%23%235812%23%2394%24%24%E4%B8%80%E8%B7%AF%E6%83%8A%E5%96%9C%E6%AD%A3%E7%89%87%23%23%2Fpy%2FlNmZoRWMp1WM_1.html%23%23271%23%234%24%24%E4%B8%80%E8%B7%AF%E6%83%8A%E5%96%9C%E9%AB%98%E6%B8%85%23%23%2Fpy%2FlNGbrBTZ2wmY_1.html%23%23477%23%238%24%24%E6%B3%95%E5%8C%BB%E7%A7%A6%E6%98%8E2%E6%B8%85%E9%81%93%E5%A4%AB%E7%AC%AC2%E9%9B%86%23%23%2Fpy%2FlNGbmZjY3YmN_2.html%23%231479%23%2368%24%24%E6%B3%95%E5%8C%BB%E7%A7%A6%E6%98%8E%E7%AC%AC03%E9%9B%86%23%23%2Fpy%2FlRmNkdmZsRmN_3.html%23%23837%23%2342%24%24%E4%BA%BA%E5%86%8D%E5%9B%A7%E9%80%94%E4%B9%8B%E6%B3%B0%E5%9B%A7%E6%AD%A3%E7%89%87%23%23%2Fpy%2FlNmZkRjYjlDa_1.html%23%231206%23%2319%24%24%E9%80%9F%E5%BA%A6%E4%B8%8E%E6%BF%80%E6%83%853%EF%BC%9A%E4%B8%9C%E4%BA%AC%E6%BC%82%E7%A7%BBHD1280%E9%AB%98%E6%B8%85%E4%B8%AD%E5%AD%97%E7%89%88%23%23%2Fpy%2FlNWZ5wWb2ADb_1.html%23%23783%23%2313%24%24%E9%80%9F%E5%BA%A6%E4%B8%8E%E6%BF%80%E6%83%856HD1280%E9%AB%98%E6%B8%85%E4%B8%AD%E8%8B%B1%E5%8F%8C%E5%AD%97%E7%89%88%23%23%2Fpy%2FlNWZ5wWb2MzZ_1.html%23%235487%23%2370%24%24%E7%88%B1%E6%83%85%E5%85%AC%E5%AF%93%E7%AC%AC02%E9%9B%86%23%23%2Fpy%2FlRWZ3kGatNDZ_2.html%23%235%23%230%24%24; _pk_ref.1.f469=%5B%22%22%2C%22%22%2C1628861961%2C%22https%3A%2F%2Fcn.bing.com%2F%22%5D; _pk_ses.1.f469=1; PHPSESSID=iihse8vlb216gg5fdg3gp1enr2; Pianku_auth=06c5N-Pw7RaPoL7AOK2gZ9aIXMWGJb9xfbzdsIoHXUhn5Z-bGs1l68_Lhs7og6jww6iG_WLRbyEnhRXTbu_vthptMBgPXAm5yYV9rJlFKV2fnCs086hqg2uotFTErgHhyApWJTPsdVY19PwZJf_HwhyE7FcC83swIfUitbx_hsbqF2XVCp-zj5IU12U; Pianku_cookietime=95b9iaLnS9KECMWRwUf-834BhwpxfnYShmmwOys_Yp0DjXcSV_C1"
}
request=Request(url,headers=headers)
response=urlopen(request)
print(response.read().decode())
老师,请问导入下面这行代码是什么意思呢?
from urllib.request import HTTPCookieProcessor


Python 全系列/第十五阶段:Python 爬虫开发/scrapy框架使用(旧) 18088楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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