selenium注入js代码
阅读原文时间:2023年07月08日阅读:1

from selenium import webdriver
from selenium.webdriver import ActionChains
import time

dr = webdriver.Chrome()
dr.get('http://www.ylq.com/neidi/yangmi/')
time.sleep(0.5)
js='''
var result=[];
var li= $(".hd.starRelation").find("li");
$.each(li,function(j,i){
var rel=$(i).find("em").text();
var starName=$(i).find("p").text();
result.push(starName+"_"+rel);
})
return result.join(",");
'''
value2 =dr.execute_script(js)
print(value2)