这种方法可行
for i in range(0,4):
div_str='//[@class="inner"]/div[%d]'%i
web.find_element_by_xpath(div_str).click()
time.sleep(1.5)
li_str='//[@class="el-scrollbar"]/div/ul/li[%d]'%i
web.find_element_by_xpath(li_str).click()
time.sleep(1.5)
for i in range(0,4):
web.find_element_by_xpath(f'//[@class="inner"]/div[{i}]').click()
time.sleep(1.5)
web.find_element_by_xpath(f'//[@class="el-scrollbar"]/div/ul/li[{i}]').click()
time.sleep(1.5)
#不过你这咋用time.sleep.........我的天
谢谢,time.sleep有什么问题吗?没操作一步等一下,怕东西未加载完全。import time
@失笑: 不是啊,假设你网速蛮你time sleep有啥用,程序不就崩了,https://www.cnblogs.com/pythonywy/p/11284800.html,看这
@小小咸鱼YwY: 行,我看看
哥,没用啊
for i in range(1,3):
web.find_element_by_xpath('//[@class="type"]/span[{i}]').click()
a = web.find_element_by_xpath('//[@class="type"]/span[{i}]').text
if a=="全部作品":
for j in range(1,5):
web.find_element_by_xpath('//[@class="inner"]/div[{j}]').click()
else:
for j in range(1,4):
web.find_element_by_xpath('//[@class="inner"]/div[{j}]').click()
报错信息:
File "D:/pycharm/selenium/bestu.py", line 172, in <module>
web.find_element_by_xpath('//*[@class="type"]/span[{i}]').click()
@失笑: F你是不是漏了....
@小小咸鱼YwY: 哦,哈哈哈哈,没注意到,我再试试
@小小咸鱼YwY: 不行,报错了,爆红,uploading-image-382913.png
@小小咸鱼YwY: 加了f,之后,f下面直接红线
@失笑: 复制粘贴会吗.......
@小小咸鱼YwY:
@失笑: 你python几的
@小小咸鱼YwY:
找到一种方法了:
for i in range(1,3):
div_str='//[@class="inner"]/div[%d]'%i
web.find_element_by_xpath(div_str).click()
a = web.find_element_by_xpath(div_str).text
if a=="全部作品":
for j in range(1,5):
div_str = '//[@class="inner"]/div[%d]'%j
web.find_element_by_xpath(div_str).click()
else:
for j in range(1,4):
div_str = '//*[@class="inner"]/div[%d]'%j
web.find_element_by_xpath(div_str).click()
我用的是python 3.7
这是python3,方式给你占位符的吧
for i in range(0,4):
web.find_element_by_xpath('//[@class="inner"]/div[%s]'%i).click()
time.sleep(1.5)
web.find_element_by_xpath('//[@class="el-scrollbar"]/div/ul/li[%s]'%i).click()
time.sleep(1.5)
'//[@class="inner"]/div[{}]'.format(i)
这个是关于python文本格式化的知识