简体   繁体   中英

I would like get all 40 struct of one HTML with BeautifulSoup - Python

Look my code below:

from bs4 import BeautifulSoup
url = 'https://www.walmart.com/browse/electronics/laptop-computers/?cat_id=3944_3951_1089430_132960&grid=false&sort=new'
response = get(url)

html_soup = BeautifulSoup(response.text, 'html.parser')
main_container_note = html_soup.find_all('div', class_='class="search-result-listview-items soft-sort') 
print(len(main_container_note)) # I need get 40 notebooks.
print(main_container_note)

Look closer at your find_all arguments. As a class, you passed in a string that again says "class=...", but you should only put in the name of the class there.

Using the following line, I was able to get 38 result elements, not sure about the missing 2:

main_container_note = html_soup.find('div', class_='search-result-listview-items').contents

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM