因此,这里的最终目标是在 Selenium 中进行网络爬行时识别与列表中任何项目的匹配项。这可能是一个愚蠢的语法错误。
代码:
criteriainactive = ['Inactive', 'Deleted', 'Terminated', 'Banned', 'Suspended']
statuscheck = re.search(criteriainactive,src)
回溯:
return _cache[type(pattern), pattern, flags]
TypeError: unhashable type: 'list'
如果有其他方法可以在网页中搜索上述列表,请告诉我。预先感谢:)
最佳答案
re.search
采用字符串或正则表达式对象作为参数,而不是列表。您可以使用类似以下内容:
import re
criteriainactive = ['Inactive', 'Deleted', 'Terminated', 'Banned', 'Suspended']
for x in criteriainactive:
statuscheck = re.search(x, src)
print(x, statuscheck)
关于Python 使用 RegEx 在网页中搜索列表中的匹配项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58858535/