【问题标题】:How can I scrape a table's header that contains an image?如何抓取包含图像的表格标题?
【发布时间】:2021-02-17 11:59:19
【问题描述】:

我正在尝试通过使用 pandas 库从 wiki 网站上抓取表格,标题由 5 部分组成:名称、星星、图像、健康状况、注释。
我成功抓取了姓名、星标和注释,但“健康”标题有一个图像而不是字符串名称。
(我想将“健康”显示为字符串而不是图像。)

import pandas as pd
pd.set_option('display.max_columns', None)
pd.set_option('display.width', None)
pd.set_option('display.max_colwidth', None)

url = pd.read_html("https://azurlane.koumakan.jp/List_of_Cargo#Min_Stats")

print("Type eq name: ")
eq_name = input(str())

#   list of cargo
if eq_name == "Type94".casefold():
        #   40cm Type 94
        df = url[1]
        df = df.drop([1, 2, 3], axis = 0)
        name_notes = df[['Name','Stars','Health','Notes']]
        print(name_notes)

【问题讨论】:

    标签: html python-3.x pandas dataframe web-scraping


    【解决方案1】:
    df = url[1]
    df.rename(columns={'Unnamed: 3':'Health'}, inplace=True)
    

    结果:

    Name Image Stars Health Notes
    0 40cm Type 94 Naval Gun Parts (Cargo) nan ★★★★★ 450 Gun Components: When equipped by Kashino: increases the FP of your Main Fleet and your CBs by 10%.
    1 Aviation Materials (Cargo) nan ★★★★ 250 Aviation Materials: When equipped by a Munition Ship: increases the AVI of your fleet by 8%.
    2 Small-Caliber Naval Gun Parts (Cargo) nan ★★★★ 250 Small-Caliber Gun Parts: When equipped by a Munition Ship: increases the FP of your Vanguard by 8%.
    3 Torpedo Materials (Cargo) nan ★★★★ 250 Torpedo Materials: When equipped by a Munition Ship: increases the TRP of your fleet by 8%.

    【讨论】:

      猜你喜欢
      • 2019-06-21
      • 2020-04-20
      • 2015-04-05
      • 1970-01-01
      • 1970-01-01
      • 2020-11-26
      • 2019-06-08
      • 1970-01-01
      • 2021-11-09
      相关资源
      最近更新 更多