Bạn có thể tạo ____ 7 vòng và gọi .get_text[]
từ nó:
import requests
from bs4 import BeautifulSoup
URL = "//www.ebay.com/sch/i.html?_from=R40&_nkw=oneplus%206t&_sacat=0&rt=nc&_udlo=150&_udhi=450"
headers = {"User-Agent": 'Mozilla/5.0 [Windows NT 10.0; Win64; x64; rv:68.0] Gecko/20100101 Firefox/68.0'}
page = requests.get[URL, headers=headers]
soup = BeautifulSoup[page.content, 'html.parser']
for price in soup.findAll["span", {"class": "s-item__price"}]:
print[price.get_text[strip=True]]
Prints:
$449.99
$449.99
$414.46
$399.00
$399.95
$349.99
$449.00
$585.00
...and son on.
Chỉnh sửa: Để in tiêu đề và giá cả, bạn có thể làm ví dụ:
for tag in soup.select['li.s-item:has[.s-item__title]:has[.s-item__price]']:
print['{: