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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Bs4 AttributeError:“NoneType”對象沒有屬性“get_text”

Bs4 AttributeError:“NoneType”對象沒有屬性“get_text”

莫回無 2023-12-09 16:51:52
我剛剛開始了一個跟蹤亞馬遜價格的應用程序項目。根據(jù)教程視頻,在這一步,當我運行代碼時,它必須顯示產(chǎn)品的名稱和價格,但唯一出現(xiàn)的是下一個錯誤:AttributeError: 'NoneType' object has no attribute 'get_text'。我已經(jīng)在其他頁面上嘗試過,并在這里修改了相同的主題,但沒有找到答案。請幫忙 ;(代碼本身:import requestsfrom bs4 import BeautifulSoupURL = 'https://www.amazon.es/dp/B07JQRWLXM/ref=nav_signin?pf_rd_r=FJX3CJC8RWFE3NPQJRNP&'headers = {"User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)  Chrome/86.0.4240.75 Safari/537.36'} page = requests.get(URL, headers=headers) soup = BeautifulSoup(page.content, 'html.parser') title = soup.find(id="productTitle").get_text() price = soup.find(id = "priceblock_ourprice").get_text() converted_price = float(price[0:3]) print(converted_price) print(title.strip())
查看完整描述

1 回答

?
UYOU

TA貢獻1878條經(jīng)驗 獲得超4個贊

您的腳本幾乎是正確的,只需使用lxml或html5lib解析器而不是html.parser:


import requests

from bs4 import BeautifulSoup


URL = 'https://www.amazon.es/dp/B07JQRWLXM/ref=nav_signin?pf_rd_r=FJX3CJC8RWFE3NPQJRNP&'


headers = {"User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36'}


page = requests.get(URL, headers=headers)


soup = BeautifulSoup(page.content, 'lxml')   # <-- change to 'lxml' or 'html5lib'


title = soup.find(id="productTitle").get_text()

price = soup.find(id = "priceblock_ourprice").get_text()

converted_price = float(price.split()[0].replace(',', '.'))   # <-- change the conversion method



print(converted_price)

print(title.strip())

印刷:


69.99

Tablet Fire 7, pantalla de 7'', 16 GB (Negro) - Incluye ofertas especiales


查看完整回答
反對 回復 2023-12-09
  • 1 回答
  • 0 關注
  • 114 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號