我想让如果发布时间中包含字符串 "3-30",就会跳出while循环
时间: 2024-01-10 13:04:00 浏览: 21
可以在 if 语句中使用 `break` 关键字来跳出 while 循环。你可以把原来的 break 语句放到 if 语句中,如下所示:
```
while is_bottom != True:
sleep_time = random.random()
time.sleep(sleep_time)
divs = browser.find_elements(By.XPATH, '//*[@id="scroller"]/div[1]/div')
print(len(divs))
for div in divs:
publish_time = div.find_element(By.CLASS_NAME, 'head-info_time_6sFQg').text
footers = div.find_elements(By.TAG_NAME, 'footer')
for footer in footers:
comment = footer.find_element(By.XPATH, 'div/div[2]/div/span').text
share = footer.find_element(By.XPATH, 'div/div[1]/div/div/span/div/span').text
like = footer.find_element(By.XPATH, 'div/div[3]/div/button/span[2]').text
if "3-30" in publish_time:
break # 如果发布时间中包含字符串 "3-30",就跳出 while 循环
```
这样,如果发布时间中包含字符串 "3-30",程序就会跳出 while 循环,停止执行。