zoukankan      html  css  js  c++  java
  • selenium模拟输入点击爬取企查查信息

    一、代码

    由于企查查有ip查询次数限制,多次查询后会要求登入账号,之后再出登入账号后的查询

    import selenium.webdriver
    from selenium.webdriver.chrome.options import Options
    
    url = "https://www.qichacha.com/"
    options = Options()
    # 不能隐藏浏览器,会被检测到,要求登入账号
    # options.add_argument('--headless')
    options.add_argument('--disable-gpu')
    options.add_argument('--user-agent="Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36"')
    driver = selenium.webdriver.Chrome(options=options)
    # 等待时间
    driver.implicitly_wait(5)
    driver.get(url)
    #获取整个页面
    # print(driver.page_source)
    # 搜索框输入
    driver.find_element_by_xpath('//*[@id="searchkey"]').send_keys("汽车贸易服务有限公司")
    # 点击查询
    driver.find_element_by_xpath('//*[@id="indexSearchForm"]/div/span/input').click()
    
    # 执行js获取整个页面
    # html = driver.execute_script("return document.documentElement.outerHTML")
    # print(html)
    
    # 获取数据
    content=driver.find_element_by_xpath('//*[@id="search-result"]').text
    print(content)
  • 相关阅读:
    Hash表解题之大数据查找
    数据结构与算法之字典树解题
    oracle存储过程学习
    mq常见问题
    通过反射构造对象
    平衡二叉树
    LinkList源码
    ArrayList源码
    JVM参数调优
    MyBatis源码图
  • 原文地址:https://www.cnblogs.com/angelyan/p/12467759.html
Copyright © 2011-2022 走看看