如何解决我想用BeautifulSoup获得一个HTML的所有40个结构-Python
在下面查看我的代码:
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)
解决方法
仔细查看您的find_all参数。作为一个类,您传入了一个再次显示“ class = ...”的字符串,但您只应在此处输入该类的名称。
使用以下行,我可以得到38个结果元素,不确定丢失的2个元素:
main_container_note = html_soup.find('div',class_='search-result-listview-items').contents
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。