0

This is my Python code:

from lxml import html
import requests

page = requests.get('https://www.amazon.com/s/ref=nb_sb_noss/133-6356864-
3426147?url=search-alias%3Daps&field-keywords=usb')

tree = html.fromstring(page.content)
title = tree.xpath('//h2[@data-attribute]/text()')

print(title)

When I print the title, this is the result I get:

['SanDisk Cruzer 64GB USB 2.0 Flash Drive (SDCZ36-064G-B35)', 'SanDisk Cruzer CZ36 64GB USB 2.0 Flash Drive Frustration-Free Packaging- SDCZ36-064G-AFFP', 'SanDisk Cruzer Blade 32GB USB 2.0 Flash Drive Frustration-Free Packaging- SDCZ50-032G-AFFP', 'Samsung 32GB BAR (METAL) USB 3.0 Flash Drive (MUF-32BA/AM)', 'SanDisk Cruzer 128GB USB 2.0 Flash Drive (SDCZ36-128G-B35)', 'SanDisk Cruzer 8GB USB 2.0 Flash Drive (SDCZ36-008G-B35)', 'Sabrent 4-Port USB 2.0 Hub with Individual Power Switches and LEDs (HB-UMLS)', 'Kingston Digital DataTraveler SE9 32GB USB 2.0 Flash Drive Silver (DTSE9H/32GBZET)', 'SanDisk 16GB 2.0 Flash Cruzer Glide USB Drive (SDCZ60-016G-B35)', 'Samsung 64GB BAR (METAL) USB 3.0 Flash Drive (MUF-64BA/AM)', 'SanDisk Cruzer 16GB USB 2.0 Flash Drive (SDCZ36-016G-B35)', 'Micro USB OTG to USB 2.0 Adapter; SD/Micro SD Card Reader With Standard USB Male & Micro USB Male Connector For Smartphones/Tablets With OTG Function', 'SanDisk Cruzer Fit CZ33 16GB USB 2.0 Low-Profile Flash Drive- SDCZ33-016G-B35', 'SanDisk Cruzer Blade 32GB USB 2.0 Flash Drive- SDCZ50-032G-B35', 'Sabrent 4-Port USB 3.0 Hub with Individual Power Switches and LEDs (HB-UM43)', 'Samsung 64GB USB 3.0 Flash Drive Fit (MUF-64BB/AM)']

Is there some way to create a list where each title of the product is listed under each other and without the ','?

Thank you very much for your help!

Moses Koledoye
  • 77,341
  • 8
  • 133
  • 139

1 Answers1

-1

Loop over the items in the list and print each one separately.

for t in title:
    print(t)
davidism
  • 121,510
  • 29
  • 395
  • 339
Jesper Fyhr Knudsen
  • 7,802
  • 2
  • 35
  • 46