爬虫爬淘宝美食

版权声明:本文为博主原创文章,如果转走了就评论说一声就好了哈。 https://blog.csdn.net/qq_36124802/article/details/80446664
#coding=utf-8
from selenium import webdriver
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

browsr = webdriver.Chrome()
wait = WebDriverWait(browsr, 10)

def search():
    # 请求首页
    browsr.get('https://www.taobao.com')
    # 判断加载是否成功
    # http://selenium-python.readthedocs.io/waits.html
        #延时相关操作
    input = wait.until(
            # 注意使用CSS选择器
         EC.presence_of_element_located((By.ID, "#q"))
        )
    print(input)
        #查看官方文档
    submit = wait.until(
        EC.element_to_be_clickable((By.CSS_SELECTOR, "#J_TSearchForm > div.search-button > button"))
        )
        #输入框输入 美食
    input.send_keys('美食')
        #点击确认按钮
    submit.click()

if __name__ == '__main__':
    search()

猜你喜欢

转载自blog.csdn.net/qq_36124802/article/details/80446664