[英]Trying to remove something from a list
我正在嘗試使用listname.remove('thing you want to remove')
從列表中刪除某些內容。 我收到一條錯誤list.remove(x): x not in list
,但我知道這是當我從代碼中刪除listname.remove
時,我想在列表中刪除的項目
代碼:
import requests
from bs4 import BeautifulSoup
import os
def GRS():
rust_skins_url = 'https://store.steampowered.com/itemstore/252490/browse/?filter=Limited'
TWS = []
r = requests.get(rust_skins_url)
soup = BeautifulSoup(r.text, 'html.parser')
images = soup.find_all('img')
for image in images:
TWS.append(image['src'])
TWS.remove('https://store.cloudflare.steamstatic.com/public/images/blank.gif')
TWS.remove('https://store.cloudflare.steamstatic.com/public/images/footerLogo_valve_new.png')
TWS.remove('https://store.cloudflare.steamstatic.com/public/images/ico/ico_facebook.gif')
TWS.remove('https://store.cloudflare.steamstatic.com/public/images/ico/ico_twitter.gif')
TWS.remove('https://store.cloudflare.steamstatic.com/public/images/login/throbber.gif')
TWS.remove('https://store.cloudflare.steamstatic.com/public/shared/images/header/logo_steam.svg?t=962016')
TWS.remove('https://store.cloudflare.steamstatic.com/public/shared/images/responsive/header_menu_hamburger.png')
TWS.remove('https://store.cloudflare.steamstatic.com/public/images/v6/logo_steam_footer.png')
TWS.remove('https://store.cloudflare.steamstatic.com/public/shared/images/responsive/header_logo.png')
TWS.remove('https://store.cloudflare.steamstatic.com/public/shared/images/responsive/logo_valve_footer.png')
return TWS
Skins = GRS()
print(Skins)
錯誤信息很明顯。 您要刪除的元素不在此列表中
TWS = ['https://store.st.dl.eccdnx.com/public/shared/images/responsive/logo_valve_footer.png',
'https://store.st.dl.eccdnx.com/public/shared/images/responsive/header_menu_hamburger.png',
'https://store.st.dl.eccdnx.com/public/shared/images/responsive/header_logo.png',
'https://store.st.dl.eccdnx.com/public/shared/images/header/logo_steam.svg?t=962016',
'https://store.st.dl.eccdnx.com/public/images/blank.gif',
'https://store.st.dl.eccdnx.com/public/images/login/throbber.gif',
'https://community.akamai.steamstatic.com/economy/image/6TMcQ7eX6E0EZl2byXi7vaVKyDk_zQLX05x6eLCFM9neAckxGDf7qU2e2gu64OnAeQ7835dW4mLBfCk4nReh8DEiv5dbPak9pbw2R_C6iyqIQZk/200fx200f',
'https://community.akamai.steamstatic.com/economy/image/6TMcQ7eX6E0EZl2byXi7vaVKyDk_zQLX05x6eLCFM9neAckxGDf7qU2e2gu64OnAeQ7835dW4mLHfCk4nReh8DEiv5dYOao4rbMwRPFnozBpIA/200fx200f',
'https://community.akamai.steamstatic.com/economy/image/6TMcQ7eX6E0EZl2byXi7vaVKyDk_zQLX05x6eLCFM9neAckxGDf7qU2e2gu64OnAeQ7835dW4mLGfCk4nReh8DEiv5daOqo8qrE_R_27f-qS274/200fx200f',
'https://community.akamai.steamstatic.com/economy/image/6TMcQ7eX6E0EZl2byXi7vaVKyDk_zQLX05x6eLCFM9neAckxGDf7qU2e2gu64OnAeQ7835dW4mLFfCk4nReh8DEiv5dbOKs9q7M3Qfi8Z_CWz2E/200fx200f',
'https://community.akamai.steamstatic.com/economy/image/6TMcQ7eX6E0EZl2byXi7vaVKyDk_zQLX05x6eLCFM9neAckxGDf7qU2e2gu64OnAeQ7835dW4mLDfCk4nReh8DEiv5dbPqA2rrw-Sf6-Vv4ZXZI/200fx200f',
'https://community.akamai.steamstatic.com/economy/image/6TMcQ7eX6E0EZl2byXi7vaVKyDk_zQLX05x6eLCFM9neAckxGDf7qU2e2gu64OnAeQ7835dW4mLAfCk4nReh8DEiv5dYOKg_rrc1Rv2-7yifJUc/200fx200f',
'https://community.akamai.steamstatic.com/economy/image/6TMcQ7eX6E0EZl2byXi7vaVKyDk_zQLX05x6eLCFM9neAckxGDf7qU2e2gu64OnAeQ7835dW4mLEfCk4nReh8DEiv5daOqw7rLc2SPy8kKkqluk/200fx200f',
'https://community.akamai.steamstatic.com/economy/image/6TMcQ7eX6E0EZl2byXi7vaVKyDk_zQLX05x6eLCFM9neAckxGDf7qU2e2gu64OnAeQ7835dW4mLCfCk4nReh8DEiv5daOq06qb0-Rvy9N_XMdlo/200fx200f',
'https://store.st.dl.eccdnx.com/public/images/v6/logo_steam_footer.png',
'https://store.st.dl.eccdnx.com/public/images/footerLogo_valve_new.png',
'https://store.st.dl.eccdnx.com/public/images/ico/ico_facebook.gif',
'https://store.st.dl.eccdnx.com/public/images/ico/ico_twitter.gif']
lst = ["https://store.cloudflare.steamstatic.com/public/images/blank.gif",
"https://store.cloudflare.steamstatic.com/public/images/footerLogo_valve_new.png",
"https://store.cloudflare.steamstatic.com/public/images/ico/ico_facebook.gif",
"https://store.cloudflare.steamstatic.com/public/images/ico/ico_twitter.gif",
"https://store.cloudflare.steamstatic.com/public/images/login/throbber.gif",
"https://store.cloudflare.steamstatic.com/public/shared/images/header/logo_steam.svg?t=962016",
'https://store.cloudflare.steamstatic.com/public/shared/images/responsive/header_menu_hamburger.png',
'https://store.cloudflare.steamstatic.com/public/images/v6/logo_steam_footer.png',
'https://store.cloudflare.steamstatic.com/public/shared/images/responsive/header_logo.png',
"https://store.cloudflare.steamstatic.com/public/shared/images/responsive/logo_valve_footer.png"
]
for i in lst:
if i in TWS:
TWS.remove(i)
else:
print(f"not in TWS: {i}")
出去:
not in TWS: https://store.cloudflare.steamstatic.com/public/images/blank.gif
not in TWS: https://store.cloudflare.steamstatic.com/public/images/footerLogo_valve_new.png
not in TWS: https://store.cloudflare.steamstatic.com/public/images/ico/ico_facebook.gif
not in TWS: https://store.cloudflare.steamstatic.com/public/images/ico/ico_twitter.gif
not in TWS: https://store.cloudflare.steamstatic.com/public/images/login/throbber.gif
not in TWS: https://store.cloudflare.steamstatic.com/public/shared/images/header/logo_steam.svg?t=962016
not in TWS: https://store.cloudflare.steamstatic.com/public/shared/images/responsive/header_menu_hamburger.png
not in TWS: https://store.cloudflare.steamstatic.com/public/images/v6/logo_steam_footer.png
not in TWS: https://store.cloudflare.steamstatic.com/public/shared/images/responsive/header_logo.png
not in TWS: https://store.cloudflare.steamstatic.com/public/shared/images/responsive/logo_valve_footer.png
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.