下面来看一个例子
url = http://jwxk.ucas.ac.cn/courseManage/saveCourse?s=9aa012dd-f96a-47c7-ba1d-ed4c824b42b6
需要截取出:url后半段的
9aa012dd-f96a-47c7-ba1d-ed4c824b42b6
用作下一步的参数提交
print(url.split("s="))
print(url.split("s=")[1])
结果分别是:
['http://jwxk.ucas.ac.cn/courseManage/saveCourse?', '9aa012dd-f96a-47c7-ba1d-ed4c824b42b6']
'9aa012dd-f96a-47c7-ba1d-ed4c824b42b6'
url.split(“s=”)[1]实现了需要的功能
如果要提取前半部分,把代码中的数组下标由1替换为0即可
类似之前R语言的处理思路:R语言 如何截取字符串特定字符前或后的字符串可以借助split()函数来实现split()函数使用方法string.split()其中string是字符串名字分割后会返回一个列表,其中的元素是切割后的字符串。再提取其中元素,即可得到特定字符前或后的字符串下面来看一个例子例子url = http://jwxk.ucas.ac.cn/courseManage/saveCourse?s=9aa012dd-f96a-47c7-ba1d-ed4c824b42b6需要截
big_list = []
noRep_stationList = list(set(station_list)) # 先去个重
for noRep_station in noRep_stationList:
# 第一个方法是list.split("")将li
import re
string = 'The append method appends a DataFrame-like object at the end of the current DataFrame.append '
pattern = 'app'
1.想要获取:之后的地址:http://198.168.1.1
print link[link.rfind(‘http:’):]
2.想要获取:前的数据:external link
print link[0:link.rfind(’:http’)]
您好,您可以使用Python中的字符串切片来提取文本中特定字符串后面的字符。例如,如果您想提取字符串"hello"后面的字符,您可以使用以下代码:
text = "This is a hello world example"
index = text.find("hello")
result = text[index+len("hello"):]
这将返回字符串" world example",即"hello"后面的所有字符。希望这可以帮助您!
muyu188: