beautifulsoup not returning all html

Alireza :
import requests
from bs4 import BeautifulSoup

r = requests.get('https://www.amazon.com/s?k=iphone+5s&ref=nb_sb_noss')
c = r.content

soup = BeautifulSoup(c, 'html.parser')

all = soup.find_all("span", {"class": "a-size-medium a-color-base a-text-normal"})

print(all)

so this is my simple script of python trying to scrape a page in amazon but not all the html is returned in the "soup" variable therefor i get nothing when trying to find a specific series of tags and extract them.

Jai :

Try the below code, it should do the trick for you. You actually missed to add headers in your code

import requests
from bs4 import BeautifulSoup
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'}
url = 'https://www.amazon.com/s?k=iphone+5s&ref=nb_sb_noss'
response = requests.get(url, headers=headers)
print(response.text)
soup = BeautifulSoup(response.content, features="lxml")
my_all = soup.find_all("span", {"class": "a-size-medium a-color-base a-text-normal"})
print(my_all)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=298031&siteId=1