1 回答
TA贡献1860条经验 获得超9个赞
**您可以通过仅使用product_wrapper类来选择所有产品,您也可以使用for loop在这里选择每个产品,您可以使用两种方式。**
from urllib.request import urlopen as uReq
from bs4 import BeautifulSoup as soup
my_url = 'https://www.microcenter.com/search/search_results.aspx?Ntk=all&sortby=match&N=4294966896+4294821085&myStore=true'
uClient = uReq(my_url)
page_html = uClient.read()
uClient.close()
page_soup = soup(page_html, 'html.parser')
containers = page_soup.findAll('li', {'class': 'product_wrapper'})
print(len(containers))
for product in containers :
#your code here
#or
#set how many product you want
productNumber = 16
for i in range(0,productNumber,1):
containers = page_soup.findAll('li', {'id': 'product_wrapper'+i})
#your code here
添加回答
举报