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

老师,反检测只能适用第一个选项卡的页面吗?我的程序是从虎牙直播的主页开始的,点击英雄联盟分类后,跳转到直播页面(在一个新的选项卡中打开的),然后,在这里检测到window.navigator.webdriver为true。这样里面的数据就爬取不到了。所以怎么解决这个问题呢?

from selenium import webdriver
from selenium.webdriver import ChromeOptions
from selenium.webdriver.common import action_chains
from selenium.webdriver.common.action_chains import ActionChains
import time


url = 'https://www.huya.com/'
option = webdriver.ChromeOptions()
option.add_experimental_option("excludeSwitches", ['enable-automation','enable-logging'])
option.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=option)
driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
  "source": """
    Object.defineProperty(navigator, 'webdriver', {
      get: () => false
    })
  """
})
driver.get(url)
time.sleep(1)
# 点击分类中的英雄联盟
# driver.find_element_by_id('hy-nav-category').click()
fenlei = driver.find_element_by_id('hy-nav-category')  # 分类tag
shubiao = ActionChains(driver)
shubiao.move_to_element(fenlei).perform() # 鼠标移动到分类上
time.sleep(2)
lol = driver.find_element_by_xpath("//div[@class='nav-expand-list nav-expand-game']/dl[1]/dd[1]")  # 英雄联盟tag
shubiao.click(lol).perform()
time.sleep(2) # 等待页面渲染
zhubo = driver.find_elements_by_xpath("//ul[@id='js-live-list']/li/span/span[@class='avatar fl']/i")
print(zhubo)
print(len(zhubo))
print(type(zhubo))
for i in zhubo:
    print(i)
    print(type(i))
    print(i.text())

Python 全系列/第十五阶段:Python 爬虫开发/爬虫基础(旧) 14866楼

image.pngimage.png

京东购物车网页.rar

再拷贝 商品详情那栏的时候 出现了内容偏移 image.png我这里用的 盒子模型 来改写的,请问老师这种做法是错误的吗

JAVA 全系列/第四阶段:网页编程和设计/CSS3(旧) 14867楼

"""开发记事本软件的菜单"""
from tkinter import *
from tkinter.filedialog import *
class Application(Frame):
    def __init__(self,master=None):
        super().__init__(master)
        self.master=master
        self.textpad=None #表示Text文本框对象
        self.pack()
        self.createWidget()
    def createWidget(self):
        #创建主菜单栏
        menubar=Menu(root)

        #创建子菜单
        menuFile=Menu(menubar)
        menuEdit=Menu(menubar)
        menuHelp=Menu(menubar)

        #将子菜单加入到主菜单栏
        menubar.add_cascade(label="文件(F)",menu=menuFile)
        menubar.add_cascade(label="编辑(E)",menu=menuEdit)
        menubar.add_cascade(label="帮助(H)",menu=menuHelp)

        #添加菜单项
        menuFile.add_command(label="新建",accelerator="ctrl+n",command=self.test)
        menuFile.add_command(label="打开",accelerator="ctrl+o",command=self.openfile)
        menuFile.add_command(label="保存", accelerator="ctrl+s", command=self.savefile)
        menuFile.add_separator()#添加分割线
        menuFile.add_command(label="退出",accelerator="ctrl+q",command=self.exit)

        #将主菜单栏加到根窗口
        root["menu"]=menubar

        #文本编辑区
        self.textpad=Text(root,width=50,height=30)
        self.textpad.pack()
    def test(self):
        self.textpad.delete('1.0','end')
        self.filename=asksaveasfilename(title="另存为",initialfile="C:/Users/14379/Desktop/新建文件夹",filetypes=[("文本文件", ".txt")],defaultextension='.txt')
        print(self.filename)
        self.savefile()
    def openfile(self):
        self.textpad.delete('1.0','end')
        with open(askopenfilename(title='打开文件'),encoding='utf-8') as f:
            self.textpad.insert(INSERT,f.read())
            self.filename=f.name
            print(f.name)
    def savefile(self):
        with open(self.filename,"w")as f:
            c=self.textpad.get(1.0,END)
            f.write(c)
    def exit(self):
        root.quit()

if __name__ == '__main__':
    root=Tk()
    root.geometry("450x300+200+300")
    root.title("关关的简单记事本")
    app=Application(master=root)
    root.mainloop()

image.png

老师你好我出现的问题是:

指定文件夹的文件在第一次打开文件时,能够成功添加到自定义文本框中,但是当我运行完后,第二次去打开上次打开过的文件后就会出现这个错误。

因为指定路径中,含有的文件不只是一个,我尝试了两个文件都会出现上方问题。

Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 14868楼

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
           .div1{
            background-color: blue;
            width: 500px;
            height: 500px;
        }
        .div2{
            background-color:pink;
            width: 200px;
            height: 200px;
            margin: 150px;
        }
    </style>
</head>
<body>
    <div class="div1">
        div1
        <div class="div2">div2</div>
    </div>
    <!-- 鼠标事件
    1.单击:click
    2.双击:dblclick
    3.鼠标按时:mousedown
    4.鼠标抬起:mouseup
    5.鼠标移动时:mousemove

    6鼠标移入时候/移出事:(不冒泡) mouseenter/mouseleave
     7鼠标移入时候/移出事:(不冒泡) mouseover/mouseout

    -->
    <script>
    var div1=document.getElementsByClassName('div1');
    var div2=document.getElementsByClassName('div2');
    function test1() {
        console.log('这是div1');
       
    }
    function test2() {
        console.log('这是div2');
       
    }
    var EVe={
       AA: function(ele,event,fun,bool){
         if(ele.addEventListener){
           ele.addEventListener(event,fun,bool)
         }else{
                ele.attaEvent('on'+event,fun,bool)
         }
       }
    }
      EVe.AA(div1,'click',test1,false)
    </script>
</body>
</html>

啥问题

image.png

WEB前端全系列/第二阶段:JavaScript编程模块/浏览器模型(BOM) 14870楼
WEB前端全系列/第一阶段:HTML5+CSS3模块/CSS3新特性 14871楼
Python 全系列/第二阶段:Python 深入与提高/GUI编程(隐藏) 14877楼
Python 全系列/第二阶段:Python 深入与提高/文件处理 14878楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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