Python 使用Selenium单击特定按钮和复选框

Python 使用Selenium单击特定按钮和复选框,python,selenium,beautifulsoup,phantomjs,web-crawler,Python,Selenium,Beautifulsoup,Phantomjs,Web Crawler,我正在尝试单击“详细信息搜索”按钮并检查“판매중인 차량" 复选框。但问题是在我试图查找“详细信息搜索”按钮时发生的 我在BeautifulSoup中使用了“查找”功能,如下所示: from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.common.exceptions import StaleElementReferenceException fr

我正在尝试单击“详细信息搜索”按钮并检查“판매중인 차량" 复选框。但问题是在我试图查找“详细信息搜索”按钮时发生的

我在BeautifulSoup中使用了“查找”功能,如下所示:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import StaleElementReferenceException
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select

from bs4 import BeautifulSoup
from time import sleep

link = 'http://www.bobaedream.co.kr/cyber/CyberCar.php?gubun=I'
driver = webdriver.PhantomJS()
driver.set_window_size(1920, 1080)
driver.get(link)
sleep(.75)

soup = BeautifulSoup(driver.page_source, "html.parser", from_encoding='utf-8')

# detail search open
detail_search = soup.find('img', alt='상세검색')
print(detail_search)
结果如下:

<img alt="상세검색" class="pointer" id="detail_search_btn" src="http://image.bobaedream.co.kr/renew/images/common_re/btn_search01.gif" title="상세검색열기">
<img alt="검색" class="pointer mr" id="search_click" src="http://image.bobaedream.co.kr/renew/images/common_re/btn_search02.gif" title="검색"> <span class="result" style="padding:0 5px 0 0;"><strong>181,959</strong>대</span> </img></img>

181959
我想要的结果是只有第一个按钮,没有第二个按钮,img alt=”검색“

然后,我想单击复选框“판매중인차량“

请给我一个建议


谢谢。

尝试更改此行:

detail_search = soup.find('img', alt='상세검색')
致:

find的签名为:

查找(名称、属性、递归、字符串、**kwargs)

其中
attrs
是一个字典,它以属性名为键,值为值。您可以在这里参考文档:
之所以会看到两个
img
,是因为一个嵌套在另一个中:

<img alt="상세검색" class="pointer" id="detail_search_btn" src="http://image.bobaedream.co.kr/renew/images/common_re/btn_search01.gif" title="상세검색열기">
    <img alt="검색" class="pointer mr" id="search_click" src="http://image.bobaedream.co.kr/renew/images/common_re/btn_search02.gif" title="검색">
        <span class="result" style="padding:0 5px 0 0;">    
        <strong>181,966</strong>대</span>
    </img>
</img>
尝试打印(img.attrs)以查看您拥有哪些属性

然后,我想单击复选框“판매중인차량“

我找不到任何与
판매중인차량在文档中,因此我需要猜测:如果要按标题搜索所有复选框,请使用以下命令:

soup.find('input', type="checkbox", title="개인")

谢谢你,Sisanard。我非常感谢你的帮助。这会产生相同的结果,
find
返回两个
img
。关于复选框的问题没有得到回答。这个答案显然是错误的。
find
对OP有效,因此无需重新格式化属性。另外:
find
从未找到多个节点。
img = soup.find('img', alt='상세검색')
src = img.attrs['src']
soup.find('input', type="checkbox", title="개인")