我试图在以下链接中获得少数产品的最佳搜索结果位置
https://www.purplle.com/search?q=hair%20fall%20shamboo
我使用以下工具从页面 ++ 获取 html 详细信息
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.purplle.com/search?q=hair%20fall%20shamboo")
from bs4 import BeautifulSoup
soup = BeautifulSoup(driver.page_source, 'html.parser')
driver.quit()
++
现在我很困惑如何从此 html 获取产品名称和位置(以获得最佳搜索排名)。
我使用下面的方法来获取产品的详细信息,但输出也有很多不需要的东西。
详细信息 = 汤.find('div', attrs={'class': 'pr'})
知道如何解决这个问题吗?
我不知道你说的职位是什么意思。但是,以下脚本可以从该页面获取不同产品的标题及其位置(据称):
from selenium import webdriver
from bs4 import BeautifulSoup
driver = webdriver.Chrome()
driver.get("https://www.purplle.com/search?q=hair%20fall%20shamboo")
soup = BeautifulSoup(driver.page_source, 'html.parser')
for item in soup.find_all(class_="prd-lstng pr"):
name = item.find_all(class_="pro-name el2")[0].text
position = item.find_all(class_="mrl5 tx-std30")[0].text
print(name,position)
driver.quit()
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句