I am trying to search a product 'Printer' in search bar automatically and retrieve only the MFR number of the products of company named EPSON. But the output which I am getting is more than what I want! It is the complete content of that class.
Here is my code
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)
Expected output is
3
C11CF75201
The example of (undesired) output of this code which I am getting is as shown :
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
Try to replace line
print(i, item.text)
with
print(i, item.find_element_by_xpath('.//div[@class="productCodes"]/div[2]/span').text)
to get required output
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.