有这样一段代码下拉框,选择分类:
<div class="widgets-selects direction-horizontal">
<div class="widgets-selects_container">选择分类<i class=""></i></div>
<div class="widgets-selects_select_container" style="display: none;">
<a href="javascript:;" class="">社会</a>
<a href="javascript:;" class="">国内</a>
<a href="javascript:;" class="">国际</a>
<a href="javascript:;" class="">体育</a>
<a href="javascript:;" class="">科技</a>
<a href="javascript:;" class="">娱乐</a>
<a href="javascript:;" class="">军事</a>
</div>
</div>
</div>
选择了第一个分类“社会”后,代码变成了这样:
<div class="widgets-selects direction-horizontal">
<div class="widgets-selects_container" data-spm-anchor-id="a2s0i.db_video_write.content.i2.4a603caaqY4ZC8">社会<i class=""></i></div>
<div class="widgets-selects_select_container" style="display: none;">
<a href="javascript:;" class="selected" data-spm-anchor-id="a2s0i.db_video_write.content.6">社会</a>
<a href="javascript:;" class="" data-spm-anchor-id="a2s0i.db_video_write.content.7">国内</a>
<a href="javascript:;" class="" data-spm-anchor-id="a2s0i.db_video_write.content.8">国际</a>
<a href="javascript:;" class="" data-spm-anchor-id="a2s0i.db_video_write.content.9">体育</a>
<a href="javascript:;" class="" data-spm-anchor-id="a2s0i.db_video_write.content.10">科技</a>
<a href="javascript:;" class="" data-spm-anchor-id="a2s0i.db_video_write.content.11">娱乐</a>
<a href="javascript:;" class="" data-spm-anchor-id="a2s0i.db_video_write.content.12">军事</a>
</div>
</div>
</div>
之前我用python selenium的操作是用click()命令点击一下“选择分类”,弹出下拉框,再在其中click()点击选择某个分类。
但我很希望能在python中用driver.execute_script()命令直接调用JavaScript实现选择某分类,可惜弄了半天也没琢磨出来,望大神来帮帮我呀,感激不尽。