首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在我的站点中使用Python Web Crawler

在我的站点中使用Python Web Crawler
EN

Stack Overflow用户
提问于 2018-07-17 04:01:40
回答 1查看 65关注 0票数 0

我在Python3.7中创建了一个Web爬虫,它提取不同的信息并将它们存储到4个不同的数组中。我现在遇到了一个我不确定如何解决的问题。我想在我的站点中使用这四个数组中的数据,并将它们放入一个由JS和HTML/CSS组成的表中。如何访问JavaScript文件中的Python文件中的信息?在创建帐户之前,我尝试在其他地方搜索,遇到了一些关于使用Json的事情,但我对这些不太熟悉,如果这是一种方法,我将非常感谢一些帮助。我将在下面发布我的代码,我将其存储在与我的其他站点文件相同的目录中。提前感谢!

代码语言:javascript
复制
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。我该怎么做呢?

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51369320

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档