【发布时间】:2019-01-04 15:13:30
【问题描述】:
在使用我的 Selenium Python 程序时,我试图跳过列入黑名单的项目,但我不知道如何使这个 sn-p 工作 -
channel = driver.find_element_by_xpath('/html/body/ytd-app/div[1]/ytd-page-manager/ytd-watch-flexy/div[3]/div[1]/div/div[7]/div[3]/ytd-video-secondary-info-renderer/div/div[2]/ytd-video-owner-renderer/a').get_attribute('aria-label')
print(channel)
print(blacklistchannels[3])
if channel in blacklistchannels:
print('Blacklisted Channel, Skipping...')
continue
else:
print('There is still a problem')
即使在打印时,频道名称和列入黑名单的项目 (3) 完全相同。它仍然跟随 else,并打印出“仍然存在问题”
任何帮助将不胜感激,谢谢!
编辑 - 那里的 continue 与 sn-p 无关,它只是为了继续一个循环。
解决方案 - .Stripping() 黑名单和频道名称,以消除我为换行符所使用的空格和 /n。
【问题讨论】:
-
显然不完全相同,但我们看不到任何数据。请同时显示
channel和blacklistedchannel -
用相关的 HTML 更新问题
-
它们不一样 - 可能是空格或其他。发送minimal reproducible example 以获得帮助 - 这段代码太模糊了。
-
在 猜测 中,
channel在某个容器中,例如一个列表 -
我会看看这个stackoverflow.com/questions/14312869/…,还有,你为什么用'继续'?