蝦皮購物 網站爬蟲
2019-08-17 更新
目錄
使用Selenium和BeautifulSoup,搜尋「後背包」,並抓出第一頁所有搜尋結果的月銷售量。
shopee_url = 'https://shopee.tw/'
from selenium import webdriver
driver = webdriver.Chrome()
driver.get(shopee_url)
q = driver.find_element_by_class_name('shopee-searchbar-input__input')
q.send_keys('後背包')
from selenium.webdriver.common.keys import Keys
q.send_keys(Keys.RETURN)
from bs4 import BeautifulSoup
soup = BeautifulSoup(driver.page_source,'lxml')
links = soup.find_all(class_="shopee-search-item-result__item")
for link in links:
driver.get(shopee_url+link['href'])
soup_lv2 = BeautifulSoup(driver.page_source,'lxml')
selling_data = soup_lv2.find_all("div", "shopee-product-info__header__sold-count")
print(selling_data)
A
Aron
以前用MIX這個名字在網路打滾,後來改為Aron。工業設計系畢業,曾任職知名品牌行銷企劃,做點設計,寫文案也寫網站;目前擔任零售業數據分析師。最近開始練格鬥和Python量化投資。