html与python交互(html与python结合)
大家好!今天让创意岭的小编来大家介绍下关于html与python交互的问题,以下是小编对此问题的归纳整理,让我们一起来看看吧。
ChatGPT国内免费在线使用,一键生成原创文章、方案、文案、工作计划、工作报告、论文、代码、作文、做题和对话答疑等等
只需要输入关键词,就能返回你想要的内容,越精准,写出的就越详细,有微信小程序端、在线网页版、PC客户端
本文目录:
一、如何用Python做HTML的页面
<html>
<body>
<form>
可获取码列表:
<select name="liscode">
<option value="01">123456</option>
<option value="02">123457</option>
<option value="03">123458</option>
<option value="04">123459</option>
<option value="05">123460</option>
<option value="06">123461</option>
</select>
<input type="submit" value="确认获取"/>
</form>
</body>
</html>
其中所有liscode是从一个txt文档上提取的,当用户点击获取一个的时候,该项即被删除。
如何用python实现呢?
做一个py脚本或exe给用户实现的话大概像下面这样:
Python code
infile = open('codelist.txt','r') codelist = infile.readlines() used_code = codelist[0] #remove用掉的code(删除行) codelist.remove(codelist[0]) infile.close() #重写文件(我不知道是否有能直接删除一行的文件操作方法) outfile = open('codelist.txt','w') for code in codelist: outfile.write(code + '\n') outfile.close() print used_code
二、发送HTML电子邮件与Python问题,怎么解决
#!/usr/bin/env pythonimport smtplibfrom email.mime.multipart import MIMEMultipartfrom email.mime.text import MIMEText# me == my email address# you == recipient's email addressme = "my@email.com"you = "your@email.com"# Create message container - the correct MIME type is multipart/alternative.msg = MIMEMultipart('alternative')msg['Subject'] = "Link"msg['From'] = memsg['To'] = you# Create the body of the message (a plain-text and an HTML version).text = "Hi!nHow are you?nHere is the link you wanted:nhttp://www.python.org"html = """
<html>
<head></head>
<body>
<p>Hi!<br>
How are you?<br>
Here is the <a href="http://www.python.org">link</a> you wanted.
</p>
</body></html>"""
# Record the MIME types of both parts - text/plain and text/html.
part1 = MIMEText(text, 'plain')
part2 = MIMEText(html, 'html')
# Attach parts into message container.
# According to RFC 2046, the last part of a multipart message, in this case
# the HTML message, is best and preferred.
msg.attach(part1)
msg.attach(part2)
# Send the message via local SMTP server.
s = smtplib.SMTP('localhost')
# sendmail function takes 3 arguments: sender's address, recipient's address
# and message to send - here it is sent as one string.
s.sendmail(me, you, msg.as_string())
s.quit()
三、如何用Python做HTML的页面
<html>
<body>
<form>
可获取码列表:
<select name="liscode">
<option value="01">123456</option>
<option value="02">123457</option>
<option value="03">123458</option>
<option value="04">123459</option>
<option value="05">123460</option>
<option value="06">123461</option>
</select>
<input type="submit" value="确认获取"/>
</form>
</body>
</html>
其中所有liscode是从一个txt文档上提取的,当用户点击获取一个的时候,该项即被删除。
如何用python实现呢?
做一个py脚本或exe给用户实现的话大概像下面这样:
Python code
infile = open('codelist.txt','r') codelist = infile.readlines() used_code = codelist[0] #remove用掉的code(删除行) codelist.remove(codelist[0]) infile.close() #重写文件(我不知道是否有能直接删除一行的文件操作方法) outfile = open('codelist.txt','w') for code in codelist: outfile.write(code + '\n') outfile.close() print used_code
四、如何用Python做HTML的页面
<html>
<body>
<form>
可获取码列表:
<select name="liscode">
<option value="01">123456</option>
<option value="02">123457</option>
<option value="03">123458</option>
<option value="04">123459</option>
<option value="05">123460</option>
<option value="06">123461</option>
</select>
<input type="submit" value="确认获取"/>
</form>
</body>
</html>
其中所有liscode是从一个txt文档上提取的,当用户点击获取一个的时候,该项即被删除。
如何用python实现呢?
做一个py脚本或exe给用户实现的话大概像下面这样:
Python code
infile = open('codelist.txt','r') codelist = infile.readlines() used_code = codelist[0] #remove用掉的code(删除行) codelist.remove(codelist[0]) infile.close() #重写文件(我不知道是否有能直接删除一行的文件操作方法) outfile = open('codelist.txt','w') for code in codelist: outfile.write(code + '\n') outfile.close() print used_code
以上就是关于html与python交互相关问题的回答。希望能帮到你,如有更多相关问题,您也可以联系我们的客服进行咨询,客服也会为您讲解更多精彩的知识和内容。
推荐阅读: