这是我的Python脚本:
from urllib.request import urlopen as uReq
from bs4 import BeautifulSoup as soup
myUrl='https://www.youtube.com/user/HolaSoyGerman/about'
uClient = uReq(myUrl)
page_html = uClient.read()
uClient.close()
page_soup = soup(page_html, "html.parser")
containers = page_soup.findAll("h1",{"class":"branded-page-header-title"})
filename="Products2.csv"
f = open(filename,"w")
headers = "Channel Name,Channel Description,Channel Social Media Links\n"
f.write(headers)
channel_name = containers[0].a.text
print("Channel Name :" + channel_name)
aboutUrl='https://www.youtube.com/user/HolaSoyGerman/about'
uClient1 = uReq(aboutUrl)
page_html1 = uClient1.read()
uClient1.close()
page_soup1 = soup(page_html1, "html.parser")
description_div = page_soup.findAll("div",{"class":"about-description
branded-page-box-padding"})
channel_description = description_div[0].pre.text
print("Channel Description :" + channel_description)
f.write(channel_name+ "," +channel_description)
links = page_soup.findAll("li",{"class":"channel-links-item"})
for link in links:
social_media = link.a.get("href")
f.write(","+" "+social_media+"\n")
f.close()
这是我的index.html代码:
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
</head>
<body>
<form>
<div class="form-group">
<div class="col-md-8">
<label for="exampleInputEmail1">Enter Url</label>
<input type="email" class="form-control" id="exampleInputEmail1"
placeholder="Email">
</div>
</div>
</form>
</body>
</html>
我想在这个index.html中编写我上面提到的Python脚本并执行它。 我希望用户在此输入中输入一个URL,这样我就可以在我的脚本中获取该值来代替硬编码的URL。如何在index.html中编写我的Python脚本并将Python脚本中的HTML输入值作为Python变量获取?