会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 133662个问题
JAVA 全系列/第五阶段:网页编程和设计/Javascript 语言(旧) 23716楼
JAVA 全系列/第十八阶段:亿级高并发电商项目_架构/编码(旧)/电商:使用Solr实现数据搜索 23717楼

from fake_useragent import UserAgent
import requests
from lxml import etree
from time import sleep

def get_html(url):
    #传递要爬取的地址
    #返回html
    headers= {"User-Agent":UserAgent().chrome}
    resp = requests.get(url,headers=headers)
    sleep(2)
    if resp.status_code == 200:
        return resp.text
    else:
        return None

def parse_list(html):
    #传递进来一个有电影列表的html
    #返回一个电影列表的url
    e = etree.HTML(html)
    list_url = ['https://maoyan.com/{}'.format(url) for url in e.xpath('//div[@class="movie-item-hover"]/a/@href')]
    return list_url

def pares_index(html):
    #传递进来一个有电影信息的html
    #返回已提取好的电影信息
    e = etree.HTML(html)
    name = e.xpath('//h1[@class="name"]/text()')
    type = e.xpath('//li[@class="ellipsis"]/a[1]/text()')
    actors = e.xpath('//li[@class="celebrity actor"]/div[@class="info"]/a/text()')
    actors = format_data(actors)
    return {"name":name,"type":type,"actors":actors}

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

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

if __name__ == '__main__':
    main()

image.png

老师,我运行后出现如上报错,然后我尝试修改了一下代码如下。

image.png

但是执行后出来的效果如下图,求帮助。

image.png

Python 全系列/第十六阶段:Python 爬虫开发/爬虫反反爬- 23718楼

.content{
    width: 100%;
    overflow: hidden;
    padding: 4px 0 12px;
}
.title{
    text-align: left;
    color: #333;
    font-size: 22px;
    font-weight: 200;
    line-height: 58px;
}
.phone-box{
    width: 100%;
    height: 614px;
}
.yang-left{
    width: 234px;
    height: 100%;
    background-color: #ff6700;
    float: left;
}
.yang-right{
    width: 992px;
    height: 614px;
    float: left;
}
.yang-left img{
    width: 234px;
    height: 614px;
}
.items1{
    width: 234px;
    height: 300px;
    background-color: #e0e0e0;
    padding: 20px 0;
    margin: 0 0 14px 14px;
    float: left;
    transition: all .2s linear;
    box-sizing: border-box;
}
.img1{
    width: 164px;
    margin-bottom: 18px;
}
.items1:hover{
    transform: translateY(-2px);
    box-shadow: 0 15px 30px rgba(0, 0, 0, .1);
}
.name1{
    width: 214px;
    height: 20.8;
    color: #333;
    font-size: 14px;
    line-height: 21px;
    margin: 0 auto 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.name2{
    width: 214px;
    height: 18px;
    color: #b0b0b0;
    font-size: 12px;
    line-height: 18px;
    margin: 0 10px 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.name3{
    width: 214px;
    height: 20.8px;
    color: #ff6700;
    font-size: 14px;
    line-height: 18px;
    margin: 0 10px 14px;
}
.big-img{
    width: 1226px;
    height: 120px;
    margin: 22px 0;
}
老师,line-height: 21px这个不加可以吗?white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsi这行代码有啥用?

WEB前端全系列/第一阶段:HTML5+CSS3模块/CSS3新特性 23719楼
Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 23720楼
JAVA 全系列/第六阶段:项目管理与SSM框架/SpringMVC 23721楼
Python 全系列/第十六阶段:Python 爬虫开发/爬虫基础(旧) 23723楼
Python 全系列/第十六阶段:Python 爬虫开发/爬虫基础(旧) 23724楼
JAVA 全系列/第四阶段:数据库与AI协同技术实战/JDBC技术(旧) 23725楼
JAVA 全系列/第二十一阶段:租房网(Spring Cloud最新架构)/Livegoods第一天 23727楼
JAVA 全系列/第五阶段:网页编程和设计/Jquery(旧) 23728楼

fileupload.rar

老师,这个文件上传一直是404错误,您帮我看下

JAVA 全系列/第六阶段:项目管理与SSM框架/SpringMVC 23729楼
Python 全系列/第九阶段:Flask百战电商后台系统/Flask百战电商后台项目 23730楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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