3C科技 娛樂遊戲 美食旅遊 時尚美妝 親子育兒 生活休閒 金融理財 健康運動 寰宇綜合

Zi 字媒體

2017-07-25T20:27:27+00:00
加入好友
使用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)

本文由aronhackcom提供 原文連結

寫了 5860316篇文章,獲得 23313次喜歡
精彩推薦