weixin_44402211
小呀么小二郎�
采纳率0%
2021-03-01 17:12

python用selenium chromedriver爬虫下载数据总出现这个问题

 

萌新提问:为什么出现这个问题,是不让我IP爬虫了吗,有什么解决方法呢,这是个内网的 网址,贴出程序请大神们帮忙看看,,感谢

 

def chrome_init(today_dir,str_time1,str_time2):
    option = webdriver.ChromeOptions()
    prefs = {'profile.default_content_settings.popups': 0, 'download.default_directory': os.path.join(today_dir,'data_'+str_time1)}
    option.add_experimental_option('prefs', prefs)
    driver = webdriver.Chrome(executable_path=r'C:\Users\m1886\AppData\Local\Google\Chrome\Application\chromedriver.exe',options=option)
    driver.implicitly_wait(30)  # 隐性等待,最长等30秒
    while True:
        driver.get("http://130.17.182.33:18889/cms/welcome.action")
        # driver.get("http://130.17.182.33:8080/cms/welcome.action")
        time.sleep(1)
        if has_element(driver):
            break
    #S输入用户名密码登录
    driver.find_element_by_id("nameinput").send_keys(Keys.CONTROL,"a")
    driver.find_element_by_id("nameinput").send_keys("chengjr1")
    driver.find_element_by_id("pwdinput").send_keys("chengjr1#")
    driver.find_element_by_class_name("login_btn").click()
    #E输入用户名密码登录
    while True:
        driver.get("http://130.17.182.33:8080/cms/report/brokenstationnum/brokenNumReport!initSearchReport.action")
        # driver.get("http://119.188.254.28:18889/cms//report/brokenstationnum/brokenNumReport!initSearchReport.action")
        time.sleep(1)
        if has_element(driver):
            break
    return driver
def has_element(d,tagname='div'):
    try:
        d.find_elements_by_xpath('//'+tagname)
        return True
    except:
        return False

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • technologist_04 CSDN技术专家团—麒麟奇 1月前

    调试看运行到哪一步出现这个错误,大概率是提交用户名密码后,服务端出错

    点赞 评论 复制链接分享