![](/img/trans.png)
[英]Extracting table contents from a website with expandable table using Python and Selenium
[英]Extracting only required details from the website using Selenium Python
我正在嘗試自動在搜索欄中搜索產品“打印機”,並且僅檢索名為EPSON的公司產品的MFR編號。 但是我得到的輸出超過了我想要的! 這是該課程的完整內容。
這是我的代碼
from selenium import webdriver
driver = webdriver.Chrome( "C:\All\chromedriver_win32\chromedriver.exe" )
driver.get('https://shop.techdata.com/searchall?b=1&kw=printer')
items = driver.find_elements_by_class_name( 'productResult' )
for i, item in enumerate(items):
if 'EPSON' in item.text:
print(i, item.text)
預期輸出為
3
C11CF75201
我得到的此代碼的(不需要的)輸出示例如下所示:
3 EPSON WORKFORCE PRO WF-4740 - MULTIFUNCTION PRINTER (COLOR)
Multifunction printer - color - ink-jet - Legal (8.5 in x 14 in) (original)
A4/Legal (media) - up to 22 ppm (copying) - up to 24 ppm (printing) - 500
sheets
- 33.6 Kbps - USB 2.0, LAN, Wi-Fi(n), USB host, NFC
TD#: 12710297
MFR#: C11CF75201
Status: Active
MSRP:
$299.99
嘗試更換線
print(i, item.text)
與
print(i, item.find_element_by_xpath('.//div[@class="productCodes"]/div[2]/span').text)
獲得所需的輸出
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.