【发布时间】:2019-12-28 23:20:31
【问题描述】:
上下文:我正在编写一个 Python 脚本来最终下载以下站点 (https://ngc.taleo.net/careersection/ngc_pro/jobsearch.ftl?lang=en&_ga=2.59113261.1016801192.1577482911-1938918126.1574124672) 上的帖子。我已经能够以编程方式导航页面以搜索关键字,单击搜索按钮并下拉过滤器字段以查找位置。
问题:我一直无法编写逻辑来找到 location 元素下的 california 复选框。有人可以看看下面的页面源 sn-p 并帮助我找到正确的逻辑来单击相应的加利福尼亚位置复选框元素吗?
这里是复选框周围页面源的 sn-p:
<div id="fieldSetId-LOCATION-level-2" class="hidden-audible">State / Province</div><div id="LOCATION-level-2" class="filter-level-title">State / Province</div><input id="LOCATION-level-2-item-0" type="checkbox" name="2160420105" title="California" class="filter-checkbox"><div class="label-wrapper"><a><label for="LOCATION-level-2-item-0" class="checkbox-label"><div class="checkboxp checkbox-unchecked"> </div><span class="valuesdiv"><span class="filter-text">California</span><span class="filter-quantity">(48)</span></span></label></a></div><input id="LOCATION-level-2-item-1" type="checkbox" name="2660420105" title="Maryland" class="filter-checkbox"><div class="label-wrapper"><a><label for="LOCATION-level-2-item-1" class="checkbox-label"><div class="checkboxp checkbox-unchecked"> </div><span class="valuesdiv"><span class="filter-text">Maryland</span><span class="filter-quantity">(42)</span></span></label></a></div><input id="LOCATION-level-2-item-2" type="checkbox" name="2360420105" title="Virginia" class="filter-checkbox"><div class="label-wrapper"><a><label for="LOCATION-level-2-item-2" class="checkbox-label"><div class="checkboxp checkbox-unchecked"> </div><span class="valuesdiv"><span class="filter-text">Virginia</span><span class="filter-quantity">(41)</span></span></label></a></div>
这是我目前拥有的 Python 脚本的 sn-p:
from selenium import webdriver
#Navigate to the main job search page
#https://stackoverflow.com/questions/37400974/unicode-error-unicodeescape-codec-cant-decode-bytes-in-position-2-3-trunca
browser = webdriver.Firefox(executable_path=r'C:\Users\etherealessence\AppData\Local\Programs\Python\Python36\geckodriver-v0.26.0-win64\geckodriver.exe')
browser.get(r'https://ngc.taleo.net/careersection/ngc_pro/jobsearch.ftl?lang=en&_ga=2.59113261.1016801192.1577482911-1938918126.1574124672')
#Fill in the "keyword" search input
keyword_element = browser.find_element_by_id('KEYWORD')
keyword_element.send_keys('SQL')
#Find search button and click
submit_button = browser.find_element_by_id('search')
submit_button.click()
#Drop down location field
location_field = browser.find_element_by_id('LOCATION-link')
location_field.click()
仅供参考,这是我第一次使用硒,所以请善待。
【问题讨论】:
标签: javascript python html selenium web-scraping