问题
I wonder if its possible to remove part of the scraped string like:
Wujek Drew / Uncle Drew
into
Uncle Drew
Of course, as it is web scraping, the titles will be different every time, so what can I do here to get the result above?
Update
I forgot to add something that need to be removed also. Wujek Drew / Uncle Drew (2018) I Will need to delete the data at the end of the string.
回答1:
To remove first part of the scraped string separated by / character you can use the following solution:
value = driver.find_element_by_xpath("element_xpath").get_attribute("innerHTML").split("/")[1]
As per your comment update if you want to extract the sub-string Uncle Drew from the string Wujek Drew / Uncle Drew (2018) you can use the following solution:
import re
value = driver.find_element_by_xpath("element_xpath").get_attribute("innerHTML")
#value='Wujek Drew / Uncle Drew (2018)'
print(re.split('[/()]',value)[1])
来源:https://stackoverflow.com/questions/52121094/how-to-retrieve-a-sub-string-from-a-string-that-changes-dynamically-with-respect