会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 134100个问题
JAVA 全系列/第一阶段:AI驱动的JAVA编程/JAVA入门和背景知识 4126楼
Python全系列/第一阶段:AI驱动的Python编程/Python入门(动画版) 4128楼

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver import ChromeOptions
from time import sleep

# 将浏览器设置为无头模式
def test_headless():
    # 设置参数,将浏览器设置为无头浏览器
    option = ChromeOptions()  # 设置属性
    option.add_argument('--headless')  # 增加内容

    # 设置驱动
    s = Service(executable_path='./chromedriver.exe')
    # 启动Chrome浏览器
    driver = webdriver.Chrome(service=s,options=option)
    # 访问页面
    driver.get('http://www.baidu.com')
    # 打印代码
    print(driver.page_source)
    # 关闭浏览器
    driver.quit()


# 给浏览器增加代理
def test_proxy1():
    # 设置参数,将浏览器设置为无头浏览器
    option = ChromeOptions()
    # 设置属性option.add_argument('--proxy-server=ip:port')
    option.add_argument('--proxy-server=http://221.199.36.122:35414')  # 增加内容

    # 设置驱动
    s = Service(executable_path='./chromedriver.exe')
    # 启动Chrome浏览器
    driver = webdriver.Chrome(service=s,options=option)
    # 访问页面
    driver.get('http://httpbin.org/get')
    # 打印代码
    print(driver.page_source)
    # 关闭浏览器
    driver.quit()


# 防止检测
def test_find():
    # 老版
    options = ChromeOptions()
    options.add_experimental_option('excludeSwitches', ['enable - automation'])
    options.add_experimental_option('useAutomationExtension', False)

    # 新版
    chrome = webdriver.Chrome(chrome_options=options)
    chrome.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
    "source": """
       Object.defineProperty(navigator,
    'webdriver', {
       get: () => false
       })
     """
    })
    chrome.get('http://httpbin.org/get')
    info = chrome.page_source
    print(info)
    sleep(100)



if __name__ == '__main__':
    test_find()

是这样的

Python全系列/第十六阶段:Python 爬虫开发/爬虫基础 4129楼
Python全系列/第九阶段:Flask百战电商后台系统/Flask百战电商后台项目 4130楼
JAVA 全系列/第六阶段:项目管理与SSM框架/Mybatis 4131楼
Python全系列/第一阶段:AI驱动的Python编程/序列 4132楼

求助:配置nginx后,一个www.123.com  (html)可以,一个www.sxthhenhao.com  (cdrom)不行,但是网页ping虚拟机会出现index(cdrom)

大数据全系列/第二阶段:大型网站高并发处理/大型网站高并发处理 4133楼

<style>
        * {
            margin: 0;
            padding: 0;
        }

        .nav {
            width: 100%;
            height: 60px;
            line-height: 60px;
            background-color: #666;
        }

        .nav ul {
            width: 1000px;
            margin: 0 auto;
        }

        .nav ul li {
            list-style: none;
            float: left;
            padding: 0 20px;
        }
       
        .nav ul::after {
            content: "";
            margin: 0 auto;
            display: block;
            clear: both;
        }
        .nav ul li a {
            text-decoration: none;
            font-size: 20px;
            color: #b0b0b0;

        }

        .nav ul li:hover {
            background-color: #222;
        }
    </style>
</head>
<body>
    <div class="nav">
        <ul>
            <li><a href="#">首页</a></li>
            <li><a href="#">电视</a></li>
            <li><a href="#">家电</a></li>
            <li><a href="#">服务</a></li>
            <li><a href="#">平板</a></li>
        </ul>
        <p>hahah</p>
    </div>
</body>

image.png

WEB前端全系列/第一阶段:HTML5+CSS3模块/浮动与定位 4136楼
JAVA 全系列/第八阶段:生产环境部署与协同开发/Docker 4137楼
WEB前端全系列/第七阶段:ECMAScript6新特性模块/ES6 第一部分 4138楼

老师,我在用post 方法的时候,后台接收数据总是出现时有时没有的情况。然后报这个错误

1618134804(1).png

这时我写php文件先写这个

print_r($_POST);php 结尾处 print_r($success); 后台才会接收到前台数据;并且返回信息,否则连后台信息也不会返回。
若这个print_r($success)不写,也不行。
1618134898(1).png
1618135088(1).png
<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <title>jqajax</title>
</head>
<style>

</style>
<body>
<div>
    用户名:<input type="text" name="usename" class="usename"><br/>
    密码:<input type="text" name="pass" class="pass"><br/>
    <button>提交</button>
</div>
<script>
    //获取类
    var usename=document.querySelector('.usename');
    var password=document.querySelector('.pass');
    var btn=document.querySelector('button');
    //提交时
    btn.onclick=function () {
        //创建一个xhr对象 准备发送ajax请求
        //考虑兼容性问题
        // if(window.XMLHttpRequest){
        //     var xhr=new XMLHttpRequest();
        // }else if(window.ActiveXObject){
        //     var xhr=new ActiveXObject();
        // }
        var xhr=new XMLHttpRequest();
        //目的:用onreadystatechange监听后台是否收到前台数据的回调函数
        xhr.onreadystatechange=function () {
            //判断前台向后台发送请求的状态 值为0 1 2 3 4
            if(xhr.readyState==4){
                //判断前端是否准备收到后台反馈得数
                if(xhr.status==200) {
                    //获取后台传送的数据
                    console.log(xhr.responseText)
                    //解析数据
                    // console.log(JSON.parse(xhr.responseText))
                }
            }
        }
        // //get 方法
        // //当准备好接收后台数据的回调函数后,着手准备发送ajax请求
        // xhr.open('get','ajax.php?name='+usename.value+'&pass='+password.value,true);
        // //设置后通过send方法发送到后台post
        // xhr.send(null);
        //post 方法
        // //当准备好接收后台数据的回调函数后,着手准备发送ajax请求
        xhr.open('post','ajax.php',true);
        //设置后通过send方法发送到后台
        var data=new FormData();
        data.append('name',usename.value);
        data.append('pass',password.value);
        xhr.send(data);
    }
</script>
</body>
</html>
//获取前台数据
//print_r($_POST);
$name=$_POST['name'];
$pass=$_POST['pass'];
$success=array('msg'=>'ok');
 //连接数据库
   $con = mysqli_connect('localhost','root','','ceshi');
   if($con){
       mysqli_query($con,"set names utf8");
       mysqli_query($con,"set character_set_client=utf8");
       mysqli_query($con,"set character_set_results=utf8");
        $sql='select * from `usename` where 1 ';
         $res=$con->query($sql);
         if($res->num_rows>0){
         $info=[];
         for($i=0;$row=$res->fetch_assoc();$i++){
         $info[$i]=$row;
         }
         }
         //判断是否登录成功
         $flag=false;
         for($j=0;$j<count($info);$j++){
         if($info[$j]['name']==$name){
         if($info[$j]['pass']==$pass){
                   $success['info']=0;
                   $flag=true;
                   break;
                  }
         }else{
          $success['info']=1;
         }
         }
         }
 else {
          $success['info']=2;
      }
       json_encode($success);
       print_r($success);
  ?>


WEB前端全系列/第六阶段:Http服务与Ajax模块(旧)/Http服务与Ajax编程 4140楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

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