[英]Trying to remove something from a list
I am trying to remove something from a list using listname.remove('thing you want to remove')
.我正在尝试使用listname.remove('thing you want to remove')
从列表中删除某些内容。 I get an error saying list.remove(x): x not in list
, but I know it is when I remove listname.remove
from the code it seems the item I wanted to remove in the list我收到一条错误list.remove(x): x not in list
,但我知道这是当我从代码中删除listname.remove
时,我想在列表中删除的项目
Code:代码:
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)
The error message is obvious.错误信息很明显。 The element you want to delete is not in this list您要删除的元素不在此列表中
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}")
out:出去:
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.