代码
from selenium import webdriver
import time
driver=webdriver.Firefox()
driver.get("https://www.baidu.com/")
bai=driver.find_element_by_id("kw")
bai.send_keys("淘宝")
a=driver.find_element_by_id("su")
a.click()
time.sleep(2)
b=driver.find_element_by_xpath(".//*[@id='1']/h3/a[1]")
b.click()
handles = driver.window_handles
driver.switch_to.window(handles[1])
c=driver.find_element_by_css_selector(".site-nav-sign > a:nth-child(1)")
c.click()
time.sleep(2)
sao=driver.find_element_by_css_selector(".icon-qrcode")
sao.click()
driver.implicitly_wait(30)
d=driver.find_element_by_id("q")
d.send_keys("电脑")
e=driver.find_element_by_css_selector(".btn-search")
e.click()
f=driver.find_element_by_css_selector("#J_NavCommonRowItems_0 > a:nth-child(8) > span:nth-child(2)")
f.click()
f1=driver.find_element_by_css_selector("#J_NavCommonRowItems_0 > a:nth-child(1) > span:nth-child(2)")
f1.click()
f2=driver.find_element_by_css_selector("#J_NavCommonRowItems_0 > a:nth-child(2) > span:nth-child(2)")
f2.click()
t=driver.find_element_by_css_selector("div.inputs:nth-child(1) > div:nth-child(1) > ul:nth-child(1) > li:nth-child(1) > input:nth-child(1)")
t.send_keys("3000")
t1=driver.find_element_by_css_selector("div.inputs:nth-child(1) > div:nth-child(1) > ul:nth-child(1) > li:nth-child(3) > input:nth-child(1)")
t1.send_keys("6000")
s=driver.find_element_by_css_selector(".J_SortbarPriceSubmit")
s.click()
k=driver.find_element_by_css_selector("#J_Itemlist_Pic_611152569196")
k.click()
handles = driver.window_handles
driver.switch_to.window(handles[2])
n=driver.find_element_by_css_selector("dl.J_Prop:nth-child(1) > dd:nth-child(2) > ul:nth-child(1) > li:nth-child(1) > a:nth-child(1) > span:nth-child(1)")
n.click()
p=driver.find_element_by_css_selector("dl.J_Prop:nth-child(2) > dd:nth-child(2) > ul:nth-child(1) > li:nth-child(1) > a:nth-child(1) > span:nth-child(1)")
p.click()
yan=driver.find_element_by_css_selector("li.tb-txt:nth-child(5) > a:nth-child(1) > span:nth-child(1)")
yan.click()
gou=driver.find_element_by_css_selector(".J_LinkAdd")
gou.click()
driver.get_screenshot_as_file("gousd.png")
图片 1.在百度上输入淘宝点击搜索 2.找到你搜索的淘宝点击它,然后登陆 3.进行扫码登陆 4.选择你要搜索的商品的信息 5.点击商品,查看商品的信息 6.吧他加入购物车
|