Selenium Webdriver弹出框 微博分享的内容控制与结果生成

browser.window_handles

for i in ugc_url_l:
js = 'window.location.href="{}"'.format(i)
browser.execute_script(js)
time.sleep(random.randint(20, 60))

browser.find_element_by_xpath('/html/body/div/div[2]/div[1]/div/div[2]/span').click()
time.sleep(random.randint(20, 60))

h0, h1 = browser.window_handles
browser.switch_to.window(h1)
weibo_start_str = 'DOAEZ朵韵诗招商网http://www.icarei.cn/'
wb_txt = browser.find_element_by_id('weiboPublisher').text.replace('【(分享来自 @今日头条)', weibo_start_str)
js = 'document.getElementById("weiboPublisher").value="{}";document.getElementById("shareIt").click();'.format(
wb_txt);
browser.execute_script(js);
time.sleep(random.randint(40, 100))
browser.close()
browser.switch_to.window(h0)
time.sleep(random.randint(40, 100))







原文地址:https://www.cnblogs.com/rsapaper/p/8358900.html