You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Python打开本地.html文件并点击提交按钮

Alternative Methods to Submit Your HTML Form (No Selenium Needed)

Got it, since you don't want to use Selenium for submitting that form, here are several straightforward alternatives that fit different use cases—no browser automation required:

1. Python with requests Library

This is one of the most common and flexible options for HTTP requests. First, make sure you have the requests package installed (pip install requests), then use this code:

import requests

url = "http://192.168.2.2/cgi-bin/http_recv.cgi"
payload = {
    "DATA_SEND": "Your text content here"  # Replace with the data you want to send
}

response = requests.post(url, data=payload)
print("Response status code:", response.status_code)
print("Response content:", response.text)

2. Command Line with curl

If you prefer quick, scriptable command-line tools, curl is perfect for this. Just run this in your terminal:

curl -X POST -d "DATA_SEND=Your text content here" http://192.168.2.2/cgi-bin/http_recv.cgi

If your content has spaces or special characters, wrap the data in quotes properly, or use --data-urlencode for safer encoding.

3. Node.js with axios or node-fetch

For JavaScript environments, you can use either axios or the built-in fetch API (Node.js 18+ has fetch by default). Here's an example with axios:

First install axios (npm install axios), then:

const axios = require('axios');

const url = "http://192.168.2.2/cgi-bin/http_recv.cgi";
const data = {
    DATA_SEND: "Your text content here"
};

axios.post(url, data)
    .then(response => {
        console.log("Response status:", response.status);
        console.log("Response data:", response.data);
    })
    .catch(error => {
        console.error("Error:", error);
    });

4. PHP with cURL Extension

If you're working in a PHP environment, you can use the cURL extension to send the POST request:

<?php
$url = "http://192.168.2.2/cgi-bin/http_recv.cgi";
$data = array('DATA_SEND' => 'Your text content here');

// Initialize cURL
$ch = curl_init($url);

// Set cURL options
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// Execute and get response
$response = curl_exec($ch);
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

// Clean up
curl_close($ch);

echo "Status Code: " . $statusCode . "\n";
echo "Response: " . $response . "\n";
?>

All these methods directly send the POST request to your CGI script, just like the HTML form would—no browser involved, which is probably why you wanted to avoid Selenium in the first place. Pick the one that fits your programming environment or workflow best!

内容的提问来源于stack exchange,提问作者skrowten_hermit

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 06:48:18