Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将按钮插入html文件或动态地将页面内容发送到服务器_Javascript_Jquery_Python_Html - Fatal编程技术网

Javascript 将按钮插入html文件或动态地将页面内容发送到服务器

Javascript 将按钮插入html文件或动态地将页面内容发送到服务器,javascript,jquery,python,html,Javascript,Jquery,Python,Html,我试图将html代码中的一个按钮放入文件中,或者在加载时动态加载。我是python系统程序员,所以我试图用python来解决它 from BeautifulSoup import BeautifulSoup, SoupStrainer html="" #Holds the mainhtml loadaed updated_html ="" #Holds the html with the new layout updated_html_file= open('reviw.htmlx', '

我试图将html代码中的一个按钮放入文件中,或者在加载时动态加载。我是python系统程序员,所以我试图用python来解决它

from BeautifulSoup import BeautifulSoup, SoupStrainer


html="" #Holds the mainhtml loadaed
updated_html =""  #Holds the html with the new layout
updated_html_file= open('reviw.htmlx', 'w'); # file pointer to the html file with action buttons
with open('aaaa.html', 'r+') as myfile:
    html=myfile.read();
    update_html=update_html.replace("</a>","</a><input type=\"button\" value=DMCA onclick=\"window.location.href='.html';\">DMCA</button>

    updated_html_file.write(update_html);    #Puts the DMCA button next to it
updated_html_file.close();

import socket;
import sys;

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM);
server_address = ('localhost', 9999);
print >>sys.stderr, 'starting up on %s port %s' % server_address;
sock.bind(server_address);
# Listen for incoming connections
sock.listen(1)

while True:
    # Wait for a connection
    print >>sys.stderr, 'waiting for a connection';
    connection, client_address = sock.accept();
    try:
        print >>sys.stderr, 'connection from', client_address;

        # Receive the data in small chunks and retransmit it;
        while True:
            data = connection.recv(16);
            print >>sys.stderr, 'received "%s"' % data;
        if data:
            print >>sys.stderr, 'sending data back to the client';
            connection.sendall(data);
        else:
            print >>sys.stderr, 'no more data from', client_address;
        break
    finally:
        # Clean up the connection
        connection.close();
从BeautifulSoup导入BeautifulSoup,SoupStrainer
html=”“#保存主html加载项
更新的_html=”“#保存具有新布局的html
更新的_html_file=open('reviw.htmlx','w');#带有操作按钮的html文件的文件指针
以open('aaaa.html','r+')作为myfile:
html=myfile.read();
update\u html=update\u html.replace(“,”DMCA
更新的html文件。写入(更新html);#将DMCA按钮放在它旁边
更新了_html_file.close();
进口插座;
导入系统;
sock=socket.socket(socket.AF_INET,socket.sock_STREAM);
服务器地址=('localhost',9999);
打印>>sys.stderr,'在%s端口%s%服务器地址上启动;
sock.bind(服务器地址);
#侦听传入的连接
短袜,听(1)
尽管如此:
#等待连接
打印>>sys.stderr,“等待连接”;
连接,客户端地址=sock.accept();
尝试:
打印>>sys.stderr,“连接自”,客户端地址;
#接收小块数据并重新传输;
尽管如此:
数据=connection.recv(16);
打印>>sys.stderr',收到“%s”数据;
如果数据:
打印>>sys.stderr,“将数据发送回客户端”;
连接.sendall(数据);
其他:
打印>>sys.stderr,“不再来自”客户端地址;
打破
最后:
#清理连接
connection.close();
现在我们有了按钮,我这里有一个服务器,它只会监听端口80并吐出它接收到的内容。我根本不知道如何将锚链接或文本发送到服务器。我在谷歌上搜索了HTML和JS,但这是我第一次用HTML触摸web,所以我既不理解也找不到任何可以理解的内容从中推断。我考虑过可能会将post方法发送到http服务器?考虑到按钮的数量,我也不知道如何实现这一点:(


作为一名真正的html新手,我能做到这一点吗?任何提示都非常感谢。

你听说过JQuery吗?我认为它使向javascript的转换变得更容易。而且Fiddler可能有助于监控正在发生的事情。你是否在寻找代码以异步方式将内容从页面发送到服务器?你必须重新注册er:Python是一个服务器端脚本。它运行一次,然后提供HTML。一旦提供HTML,Python就不能更改它-只有JavaScript可以。我建议你做一个JavaScript教程-你必须在某个时候学习它,才能对网站做任何有用的事情。正如@Lola所提到的,一旦你了解了一些JS,看看JQuery:这是一个非常有用的工具很好的简单/功能强大的JS库,用于做很多常见的事情(如网络请求)。