[英]Remove substring from array of python strings
I have an array of strings that I am scraping that looks like this ["https://rotogrinders.com/players/charlie-culberson-13456?format=json", "https://rotogrinders.com/players/charlie-culberson-13456?format=json"]
我有一个要抓取的字符串数组,看起来像这样["https://rotogrinders.com/players/charlie-culberson-13456?format=json", "https://rotogrinders.com/players/charlie-culberson-13456?format=json"]
I want to remove the https://rotogrinders.com/players/
part from each string in the array. 我想从数组中的每个字符串中删除https://rotogrinders.com/players/
部分。 How would I do this? 我该怎么做?
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
browser = webdriver.Chrome("/ProgramData/chocolatey/bin/chromedriver.exe")
browser.get("https://rotogrinders.com/projected-stats/mlb-hitter?site=fanduel")
# Wait 20 seconds for page to load
timeout = 20
try:
WebDriverWait(browser, timeout).until(EC.visibility_of_element_located((By.CLASS_NAME, 'player-popup')))
except TimeoutException:
print("Timed out waiting for page to load")
browser.quit()
# find_elements_by_xpath returns an array of selenium objects.
players_info = []
players = browser.find_elements_by_css_selector('div.player')
for player in players:
link = player.find_element_by_class_name('player-popup')
players_info.append(link.get_attribute('href'))
You could simply do: 您可以简单地执行以下操作:
listbase = ["https://rotogrinders.com/players/charlie-culberson-13456?format=json",
"https://rotogrinders.com/players/charlie-culberson-13456?format=json"]
_list = [element.split("/", maxsplit=4)[-1] for element in listbase]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.