简而言之,我的代码应该从网站的HTML中的特定标记中提取文本(借助beautifulsoup4),然后将它们加载到一个数组中。你知道吗
我尝试过各种方法,但无法将多行字符串连接到单个数组中。你会怎么做?打印productBrands
逐行返回文本。你知道吗
当前代码:
soup = BeautifulSoup(response.content)
productData = soup.find_all("div", {"class": "detail"})
for item in productData:
productBrands = item.contents[1].text
如果希望将每一行作为数组
productBrands
中的一个元素,那么可以创建一个空列表,并使用append
将每一行添加到数组中。你知道吗据我所知,您需要在列表中收集
get_text()
的结果:请注意,在本例中,有一种较短的方法来定位元素—使用CSS选择器:
相关问题 更多 >
编程相关推荐