• 使用selenium实现站长素材图片采集


    from selenium import webdriver
    import requests,os
    from lxml import etree
    from selenium.webdriver.chrome.options import Options
    from urllib import request
    
    chrome_options = Options()
    chrome_options.add_argument('--headless')
    chrome_options.add_argument('--disable-gpu')   #跳过视图界面
    
    pro = webdriver.Chrome(executable_path='./chromedriver.exe',options=chrome_options)
    
    url = "http://sc.chinaz.com/tupian/haiyangshengwutupian.html"
    pro.get(url)
    js = 'window.scrollTo(0,document.body.scrollHeight)'
    pro.execute_script(js)
    page_text = pro.page_source
    
    tree = etree.HTML(page_text)
    url_img = tree.xpath('//div[@id="container"]/div[@class="box picblock col3 masonry-brick"]/div/a/img/@src')  #获取图片url列表
    names = tree.xpath('//div[@id="container"]/div[@class="box picblock col3 masonry-brick"]/div/a/@alt')   #图片名称列表
    
    if not os.path.exists('./img'):  #生成文件夹
        os.mkdir('./img')    
    for index,url in enumerate(url_img):
        img_path = './img/' + names[index]+'.jpg'  #提取图片名称
        request.urlretrieve(url,img_path)
    

      

  • 相关阅读:
    PRTG安装
    如何诊断windows性能问题
    windows性能监控
    PAM 認 證 模 組
    RHEL磁盘修复
    RHEL下修改市区
    Recover database using backup controlfile until cancel
    Cancel-Based Recovery
    北京、上海的人口并不多
    swoole中http_server的配置与使用
  • 原文地址:https://www.cnblogs.com/wangtaobiu/p/10821077.html
Copyright © 2020-2023  润新知