from
selenium
import
webdriver
from
selenium.webdriver.support
import
expected_conditions as EC
from
selenium.webdriver.support.ui
import
WebDriverWait
from
selenium.webdriver.common.by
import
By
import
time
browser
=
webdriver.Chrome()
browser.get(
'https://www.taobao.com/'
)
wait
=
WebDriverWait(browser,
8
)
input
=
wait.until(EC.presence_of_element_located((By.
ID
,
'q'
)))
input
.send_keys(
'手机'
)
button
=
wait.until(EC.presence_of_element_located((By.CLASS_NAME,
'btn-search.tb-bg'
)))
button.click()
time.sleep(
15
)
img
=
wait.until(EC.presence_of_all_elements_located((By.CLASS_NAME,
'J_ItemPic.img'
)))
price
=
wait.until(EC.presence_of_all_elements_located((By.CLASS_NAME,
'price.g_price.g_price-highlight'
)))
name
=
wait.until(EC.presence_of_all_elements_located((By.CLASS_NAME,
'J_ClickStat'
)))
num
=
0
for
i
in
img:
print
(
'第'
,num
+
1
,
'个商品介绍:'
)
print
(
'img:'
,i.get_attribute(
'src'
))
print
(
'price:'
,price[num].text)
print
(
'name:'
,name[num].text)
num
=
num
+
1