例如
bs = BeautifulSoup("<html><a>sometext</a></html>")
print bs.find_all("a",text=re.compile(r"some"))
Run Code Online (Sandbox Code Playgroud)
返回[<a>sometext</a>],但当搜索的元素有一个孩子,即img
bs = BeautifulSoup("<html><a>sometext<img /></a></html>")
print bs.find_all("a",text=re.compile(r"some"))
Run Code Online (Sandbox Code Playgroud)
它返回 []
有没有办法用来find_all匹配后面的例子?
python程序如何知道它是否正在被测试?例如:
def foo():
if foo_being_tested:
pseudorandom()
else:
random()
Run Code Online (Sandbox Code Playgroud)
在测试时,程序应使用伪随机序列,以便能够与程序的 C 代码版本进行比较,并且在常规执行中numpy应使用随机序列。