网站:https://ca.cartier.com/en-ca/collections/jewelry/categories.viewall.html
查看每个产品的所有信息,并将其复制到excel文件中进行进一步的图表/分析
我一直在遵循这里的文档:https://www.crummy.com/software/BeautifulSoup/bs4/doc/#searching-by-css-class
到目前为止,工作一无所获:
import requests
from bs4 import BeautifulSoup
from bs4 import NavigableString
url = "https://ca.cartier.com/en-ca/collections/jewelry/categories.viewall.html"
headers = {'User-Agent': 'Mozilla/5.0'}
page = requests.get(url)
soup = BeautifulSoup(page.text, 'lxml')
lst =[]
for my_items in soup.find_all("div", attrs={"class": "grid-item"}):
print(my_items)
页面是动态加载的,因此
requests
不支持它。但是,可以通过向以下对象发送GET
请求来获取数据:响应数据是一个Python字典(
dict
),您可以在其中访问key
/value
:另一种方法是使用Selenium来刮取页面
安装时使用:
pip install selenium
从here下载正确的ChromeDriver
在您的示例中:
相关问题 更多 >
编程相关推荐