Reputation: 58
When I try find_all I get that error AttributeError:
'NavigableString' object has no attribute 'find_all'
import requests
from bs4 import BeautifulSoup as bs
url = "https://www.gittigidiyor.com/bilgisayar-tablet/huawei-matebook-d-14-amd-53010wpx-dizustu-bilgisayar-laptop_pdp_555531393"
r = requests.get(url)
soup = bs(r.content, "lxml")
data = soup.find("div", attrs = {"class":"gg-w-24 gg-d-24 gg-t-24 gg-m-24 padding-none-m"})
for i in data:
price = i.find("div", attrs = {"id":"sp-price-lowPrice"})
print(price.text)
Upvotes: 1
Views: 2523
Reputation: 3503
There is only one item with class "gg-w-24 gg-d-24 gg-t-24 gg-m-24 padding-none-m" and only one item with id "sp-price-lowPrice" on that page. As such why not simply do:
price = soup.find("div", attrs = {"id":"sp-price-lowPrice"})
If you do expect multiple items having "gg-w-24 gg-d-24 gg-t-24 gg-m-24 padding-none-m", then amend data to:
data = soup.find_all("div", attrs = {"class":"gg-w-24 gg-d-24 gg-t-24 gg-m-24 padding-none-m"})
# for i in data:
#... rest of your code here
Upvotes: 1