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

老师麻烦帮我看下代码,我的ip好像是不是被封了?响应回来的html好像是要我验证

import requests
from fake_useragent import UserAgent
from lxml import etree

def get_html(url):
    '''传入要爬取的地址,返回html'''
    headers = {"User-Agent": UserAgent().chrome}
    response = requests.get(url,headers)
    if response.status_code == 200:
        response.encoding = 'utf-8'
        print(response.text)
        return response.text
    else:
        return None         

def parse_list(html):
    '''传入含有电影信息的html,返回电影列表的每个电影的html'''
    e = etree.HTML(html)
    list_url = ['https://maoyan.com/{}'.format(url) for url in e.xpath('//div[@class="movie-item film-channel"]/a/@href')]
    # print(list_url)
    return list_url

def parse_index(html):
    '''传入有电影信息的html,返回提取到的电影信息'''
    e = etree.HTML(html)
    name = e.xpath('//h1[@class="name"]/text()') 
    type = e.xpath('//li[@class="ellipsis"][1]/a/text()')
    actor = e.xpath('//div[@class="celebrity-group"][2]/ul[@class="celebrity-list clearfix"]/li/div/a/text()')
    actors = format_data(actor)
    return {'name':name,'type':type,'actor':actors}

def format_data(actors):
    actor_set = set()
    for actor in actors:
        actor_set.add(actor)
    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)
        print(list_url)
        # for url in list_url:
        #     info_html = get_html(url)
        #     movie = parse_index(info_html)
        #     print(movie)


if __name__ == "__main__":
    main()

image.png

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

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<style>
    li{background-color: skyblue}
    li:hover{
        background-color: #ff6700;
    }
</style>
<body>
    <button id="button1">获取元素</button>
    <button id="button2">设置元素</button>
    <button id="button3">删除元素</button>

<script>
    var div1=document.createElement('div');
    div1.style.cssText='width:100%;position:relative;background:red;';
    var div2=document.createElement('div');
    div2.style.cssText='width:80%;position: absolute;left: 50%;transform: translateX(-50%)';
    document.body.appendChild(div1);
    var arr=['首页','军事','科技','新闻','游戏'];
    var ul=document.createElement('ul');
    ul.style.cssText='margin:0;padding:0;list-style;text-align: center;background:pink;';
    for (var i=0;i<arr.length;i++){
        var li=document.createElement('li');
        li.style.cssText='display: inline-block;  width: 100px;height: 30px;  line-height: 30px;\
                        text-align: center;  margin-left:5px';
        var a=document.createElement('a');
        a.style.cssText=' text-decoration: none;color: white;';
        a.innerHTML=arr[i];
        li.appendChild(a);
        ul.appendChild(li);
    }
    div2.appendChild(ul);
    div1.appendChild(div2);
    document.body.appendChild(div1);

    var button=document.querySelector('div');
    document.querySelector('#button1').onclick=function () {
       console.log( button.getAttribute('style'));
    };
    document.querySelector('#button2').onclick=function () {
        button.setAttribute('style','display:none');
    };
    document.querySelector('#button3').onclick=function () {
        button.removeAttribute('style');
    }
</script>

</body>
</html>

老师为啥我div1颜色设置不出来

WEB前端全系列/第二阶段:JavaScript编程模块/DOM模型 26120楼
JAVA 全系列/第一阶段:JAVA 快速入门/JAVA入门和背景知识 26122楼
JAVA 全系列/第二十一阶段:分布式医疗云平台/进销存系统前后端开发(旧) 26126楼
Python 全系列/第一阶段:Python入门/Python入门(动画版) 26127楼
Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 26128楼

egoshop.rar

productList这个文件在操作删除的时候,点击删除  会删除整个数据库数据,找不到为什么,麻烦老师看下

WEB前端全系列/第二十阶段:Vue2企业级项目(旧)/Ego商城高级Vue实战项目 26129楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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