我正在尝试从页面中替换数据,所有的项目都是这样存储的
<div class="box browsingitem canBuy 123"> </div>
<div class="box browsingitem canBuy 264"> </div>
有数百个,但当我试图将它们添加到数组中,它只保存24个
from urllib.request import urlopen as uReq
from bs4 import BeautifulSoup as soup
import re
import lxml
my_url = 'https://www.alza.co.uk/tablets/18852388.htm'
uClient = uReq(my_url)
page_html = uClient.read()
uClient.close()
page_soup = soup(page_html, "lxml")
classname = "box browsingitem"
containers = page_soup.find_all("div", {"class":re.compile(classname)})
#len(containers) will be equal to 24
for container in containers:
title_container = container.find_all("a",{"class":"name browsinglink"})
product_name = title_container[0].text
print("product_name: " + product_name)
重新编译有问题吗?不然我怎么找这些课程呢
谢谢你的帮助
因此,在本例中,当您访问页面时,DOM中只加载了24个项。我想到的两个选项是:1)使用无头浏览器单击“加载更多”按钮并将更多项目加载到DOM;2)创建简单的分页方案并循环浏览这些页面
下面是第二个选项的示例:
您可以看到url内置了分页信息,所以您所需要做的就是确定要刮取多少页,然后可以保存所有这些信息。以下是输出:
相关问题 更多 >
编程相关推荐