!pip install requests
!pip install bs4
import requests
from bs4 import BeautifulSoup
url = "https://www.amazon.in/Apple-iPhone-Pro-Max-256GB/dp/B07XVLH744/ref=sr_1_1_sspa?crid=2VCKZNOH3H6SR&keywords=apple+iphone+11+pro+max&qid=1582043410&sprefix=apple+iphone%2Caps%2C388&sr=8-1-spons&psc=1&spLa=ZW5jcnlwdGVkUXVhbGlmaWVyPUEyVjdZSE83TzU4UUMmZW5jcnlwdGVkSWQ9QTAyNTI1ODZJUzZOVUwxWDNIUlAmZW5jcnlwdGVkQWRJZD1BMDkxNDg4MzFLMFpVT1M5OFM5Q0smd2lkZ2V0TmFtZT1zcF9hdGYmYWN0aW9uPWNsaWNrUmVkaXJlY3QmZG9Ob3RMb2dDbGljaz10cnVl"
headers = {"User-Agent": "in this section im adding my user agent after typing my user agent in google search"}
page = requests.get(url, headers=headers)
soup = BeautifulSoup(page.content, "html.parser")
print(soup.prettify())
title = soup.find(id = "productTitle").get_text()
price = soup.find(id = "priceblock_ourprice").get_text()
converted_price = price[0:8]
print(converted_price)
print(titles)
我正在谷歌colab上工作,当我运行这个代码时,我得到这个错误
AttributeError Traceback (most recent call last)
<ipython-input-15-14696d9dc778> in <module>()
16 print(soup.prettify())
17
---> 18 title = soup.find(id = "productTitle").get_text()
19 price = soup.find(id = "priceblock_ourprice").get_text()
20
AttributeError: 'NoneType' object has no attribute 'get_text'
我尝试在互联网上搜索,但没有找到解决我问题的答案。我试图得到iPhone 11专业最高价格。当我运行此代码时,我得到上面提到的错误。
白衣非少年
交互式爱情
慕盖茨4494581
繁星淼淼
相关分类