我在Python3.7中创建了一个Web爬虫,它提取不同的信息并将它们存储到4个不同的数组中。我现在遇到了一个我不确定如何解决的问题。我想在我的站点中使用这四个数组中的数据,并将它们放入一个由JS和HTML/CSS组成的表中。如何访问JavaScript文件中的Python文件中的信息?在创建帐户之前,我尝试在其他地方搜索,遇到了一些关于使用Json的事情,但我对这些不太熟悉,如果这是一种方法,我将非常感谢一些帮助。我将在下面发布我的代码,我将其存储在与我的其他站点文件相同的目录中。提前感谢!
from requests import get
from bs4 import BeautifulSoup
from flask import Flask
app = Flask(__name__)
@app.route("/")
def main():
# lists to store data
names = []
gp = []
collectionScore = []
arenaRank = []
url = 'https://swgoh.gg/g/21284/gid-1-800-druidia/'
response = get(url)
soup = BeautifulSoup(response.content, 'html.parser')
# username of the guild members:
for users in soup.findAll('strong'):
if users.text.strip().encode("utf-8") != '':
if users.text.strip().encode("utf-8") == '\xe9\x82\x93\xe6\xb5\xb7':
names.append('Deniz')
else:
names.append(users.text.strip().encode("utf-8"))
if users.text.strip().encode("utf-8") == 'Note':
names.remove('Note')
if users.text.strip().encode("utf-8") == 'GP':
names.remove('GP')
if users.text.strip().encode("utf-8") == 'CS':
names.remove('CS')
print(names)
# GP of the guild members:
for galacticPower in soup.find_all('td', class_='text-center'):
gp.append(galacticPower.text.strip().encode("utf-8"))
totLen = len(gp)
i = 0
finGP = []
while i < totLen:
finGP.append(gp[i])
i += 4
print(finGP)
# CS of the guild members:
j = 1
while j < totLen:
collectionScore.append(gp[j])
j += 4
print(collectionScore)
# Arena rank of guild member:
k = 2
while k < totLen:
arenaRank.append(gp[k])
k += 4
print(arenaRank)
if __name__ == "__main__":
app.run()
我想在JavaScript或HTML文件中使用四个列表-- finGP、names、collectionScore和arenaRank。我该怎么做呢?
https://stackoverflow.com/questions/51369320
复制相似问题