我正在尝试从Zalora获取以下三个内容: 1商品品牌 2项目名称 三。项目价格(旧)
以下是我的初步尝试:
from bs4 import BeautifulSoup
import requests
def make_soup(url):
html = requests.get(url)
bsObj = BeautifulSoup(html.text, 'html.parser')
return bsObj
soup = make_soup('https://www.zalora.com.hk/men/clothing/shirt/?gender=men&dir=desc&sort=popularity&category_id=31&enable_visual_sort=1')
itemBrand = soup.find("span",{"class":"b-catalogList__itmBrand fsm txtDark uc js-catalogProductTitle"})
itemName = soup.find("em",{"class":"b-catalogList__itmTitle fss"})
itemPrice = soup.find("span",{"class":"b-catalogList__itmPrice old"})
print(itemBrand, itemName, itemPrice)
输出:
^{pr2}$然后我做进一步的调查:
productsCatalog = soup.find("ul",{"id":"productsCatalog"})
print(productsCatalog)
输出:
<ul class="b-catalogList__wrapper clearfix" id="productsCatalog">
这是一件让我困惑的奇怪的事情,ul标签中应该有很多标签(我需要的3件东西都在那些隐藏的标签中),为什么它们没有出现?在
事实上,我在ul标记中尝试使用beauthoulsoup来获取的所有内容都没有输出。在
由于此内容是由JavaScript呈现的,因此不能使用}。在
requests
模块访问它。您应该使用selenium
使浏览器自动化,然后使用BeautifulSoup
来解析实际的{这是使用
selenium
和{a1}一起使用的方法:输出:
^{pr2}$相关问题 更多 >
编程相关推荐