我试图从这些裤子中提取价格并将其放入变量中。我看到其他解决方案在 html 中有类似“itemprop”的内容,但我的没有。
这是一个屏幕截图:
这是我到目前为止的代码:
import requests
import time
from bs4 import BeautifulSoup
import json
url = 'https://www.urbanoutfitters.com/search?q=cargo%20pant&sayt=true'
headers = {'User-Agent':'Mozilla/5.0'}
response = requests.get(url, headers = headers)
response.status_code
print (response)
soup = BeautifulSoup(response.content,'html.parser')
page = requests.get("https://www.patagonia.ca/shop/mens-hard-shell-jackets-vests")
soup = BeautifulSoup(page.content, 'html.parser')
div_price = []
# Loop on elements
for pant in soup.find_all('p', {'class':'c-pwa-product-price c-pwa-product-tile__price'}):
span_price = pant.find('span', {'aria-label': 'class'})
if span_price:
div_price.append(span_price.get('content'))
print(div_price)
谢谢!!!!
绝地无双
相关分类