第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Beautifulsoup 無(wú)法抓取元素

Beautifulsoup 無(wú)法抓取元素

烙印99 2023-09-19 13:57:10
您好,我嘗試抓取以下網(wǎng)站: https: //www.footlocker.co.uk/en/all/new/我想抓取以下元素的價(jià)格和“href”:<span class=" fl-price--sale ">    <meta itemprop="priceCurrency" content="GBP">    <meta itemprop="price" content="84.99"><span>£ 84,99</span></span>和這個(gè)(參考):<a href="https://www.footlocker.co.uk/en/p/adidas-performance-don-issue-2-men-shoes-92815?v=314102617504#!searchCategory=all" data-product-click-link="314102617504" data-hash-key="searchCategory" data-hash-url="https://www.footlocker.co.uk/en/p/adidas-performance-don-issue-2-men-shoes-92815?v=314102617504" data-testid="fl-product-details-link-314102617504">我試過(guò)這段代碼:import urllib.requestimport bs4 as bsfrom bs4 import BeautifulSoupimport requestsproxies = {'type':'ip:port'}r= requests.get('https://www.footlocker.de/de/alle/new/', proxies=proxies)soup = BeautifulSoup(r.content,'html.parser')# It doesn't find it...for a in (soup.find_all('a')):    try:        if a['href'] == 'https://www.footlocker.co.uk/en/p/adidas-performance-don-issue-2-men-shoes-92815?v=314102617504#!searchCategory=all':            print(a['href'])    except:        pass# It don't find it...for price in (soup.find_all('span', class_=' fl-price--sale ')):    print(price.text)我嘗試使用代理抓取,但他拒絕抓取元素(我認(rèn)為 HTML 不正確)感謝您的建議:-)(僅用于教育建議)
查看完整描述

1 回答

?
不負(fù)相思意

TA貢獻(xiàn)1777條經(jīng)驗(yàn) 獲得超10個(gè)贊

要獲取產(chǎn)品的名稱、鏈接和價(jià)格,您可以使用以下示例:


import requests

from bs4 import BeautifulSoup



url = 'https://www.footlocker.co.uk/INTERSHOP/web/FLE/Footlocker-Footlocker_GB-Site/en_GB/-/GBP/ViewStandardCatalog-ProductPagingAjax?SearchParameter=____&sale=new&MultiCategoryPathAssignment=all&PageNumber={}'


for page in range(3):  # <--- increase the number of pages here

    print('Page {}...'.format(page))

    data = requests.get(url.format(page)).json()

    soup = BeautifulSoup(data['content'], 'html.parser')


    for d in soup.select('[data-request]'):

        s = BeautifulSoup(requests.get(d['data-request']).json()['content'], 'html.parser')

        

        print(s.select_one('[itemprop="name"]').text)

        print(s.select_one('[itemprop="price"]')['content'], s.select_one('[itemprop="priceCurrency"]')['content'])

        print(s.a['href'])

        print('-' * 80)

印刷:


Page 0...

adidas Performance Don Issue 2 - Men Shoes

84.99 GBP

https://www.footlocker.co.uk/en/p/adidas-performance-don-issue-2-men-shoes-92815?v=314102617504

--------------------------------------------------------------------------------

Nike Air Force 1 Crater - Women Shoes

94.99 GBP

https://www.footlocker.co.uk/en/p/nike-air-force-1-crater-women-shoes-98071?v=315349054502

--------------------------------------------------------------------------------

Jordan Jumpmcn Cl Iii Camo - Baby Tracksuits

39.99 GBP

https://www.footlocker.co.uk/en/p/jordan-jumpmcn-cl-iii-camo-baby-tracksuits-91611?v=318280390044

--------------------------------------------------------------------------------

Jordan 13 Retro - Grade School Shoes

99.99 GBP

https://www.footlocker.co.uk/en/p/jordan-13-retro-grade-school-shoes-952?v=316701533404

--------------------------------------------------------------------------------


...and so on.


查看完整回答
反對(duì) 回復(fù) 2023-09-19
  • 1 回答
  • 0 關(guān)注
  • 161 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)