51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 941|回复: 3
打印 上一主题 下一主题

selenium错误

[复制链接]
  • TA的每日心情
    无聊
    4 天前
  • 签到天数: 530 天

    连续签到: 2 天

    [LV.9]测试副司令

    跳转到指定楼层
    1#
    发表于 2022-4-11 13:30:39 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
    1测试积点

    1. # _*_coding:utf-8_*_
    2. # ! python 3.8
    3. # This is the code for selenium to get the comixes.
    4. """
    5. # Author_by uFTvL9
    6. # the first page of the ComiX is
    7. https://xmanhua.com/m11156/
    8. """
    9. # import_list
    10. from selenium import webdriver
    11. from selenium.webdriver.support.ui import WebDriverWait
    12. from selenium.webdriver.common.by import By
    13. import requests
    14. import os
    15. import random


    16. def init():
    17.     print("-" * 70)
    18.     print("\t\tPlease imput your target comix URL")
    19.     # url = input()
    20.     url = 'https://xmanhua.com/m11156/'
    21.     print("Webdriver is opening your website. Please wait...")
    22.     return url


    23. def get_page(driver, url):
    24.     # Download the page
    25.     driver.get(str(url))
    26.     print("Implicitly waiting...")
    27.     driver.implicitly_wait(10)
    28.     print("WebDriver waiting...")
    29.     WebDriverWait(driver, 25)
    30.     # driver.maximize_window() # maximize the window(full screen)
    31.     html = driver.page_source
    32.     print(html)
    33.     return html


    34. def search(driver, char, element):
    35.     # Find the URL of the comic image.
    36.     if char == '#':
    37.         driver.implicitly_wait(5)
    38.         Image_element = driver.find_element(By.ID, str(element))
    39.         Image_element.get_attribute('src')
    40.         return Image_element


    41. def download_image(comicUrl):
    42.     # Download the image
    43.     print('Downloading image...')
    44.     headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:98.0) Gecko/20100101 Firefox/98.0'}
    45.     proxy = [{'http': 'http://180.110.212.36:8118'}, {'http': 'http://122.246.49.135:8010'},
    46.              {'http': 'http://111.155.116.245:8123'}, {'http': 'http://123.56.169.22:3128'}]
    47.     proxies = random.choice(proxy)
    48.     folder_name = "To you who will not perish"
    49.     print(proxies)
    50.     try:
    51.         imgFile = requests.get(comicUrl, headers=headers, proxies=proxies)
    52.         if imgFile.status_code == 200 or imgFile.status_code == 304:
    53.             imageFile = open(os.path.join(folder_name, os.path.basename(image_name)), 'wb')
    54.             for chunk in res.iter_content(100000):
    55.                 imageFile.write(chunk)
    56.                 imageFile.close()
    57.     except Exception as exc:
    58.         print('There was a problem %s' % exc)


    59. '''
    60. def get_PrevLink(soup, varstr):
    61.     # Get the button's url.
    62. '''


    63. def main():
    64.     url = 'https://xmanhua.com/m11156/'
    65.     driver = webdriver.Firefox()
    66.     get_page(driver, url)
    67.     Image_url = search(driver, "#", "cp_image")
    68.     download_image(str(Image_url))
    69.     driver.quit()
    70.     print('Done')


    71. if __name__ == "__main__":
    72.     main()
    复制代码
    出现错误
    1. There was a problem Invalid URL '<selenium.webdriver.remote.webelement.WebElement (session="88990c6b-f1ea-413d-9ab6-101e03161420", element="e17b5c1a-1739-49ea-b4d1-d7c10ac994eb")>': No scheme supplied. Perhaps you meant http://<selenium.webdriver.remote.webelement.WebElement (session="88990c6b-f1ea-413d-9ab6-101e03161420", element="e17b5c1a-1739-49ea-b4d1-d7c10ac994eb")>?
    2. Done
    复制代码
    如何解决?

    分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏
    回复

    使用道具 举报

  • TA的每日心情
    慵懒
    前天 08:51
  • 签到天数: 668 天

    连续签到: 6 天

    [LV.9]测试副司令

    2#
    发表于 2022-4-12 10:05:24 | 只看该作者
    不清楚
    回复

    使用道具 举报

  • TA的每日心情
    慵懒
    3 天前
  • 签到天数: 1521 天

    连续签到: 5 天

    [LV.Master]测试大本营

    3#
    发表于 2022-4-12 10:38:05 | 只看该作者
    session失效?
    回复

    使用道具 举报

  • TA的每日心情
    奋斗
    22 分钟前
  • 签到天数: 2819 天

    连续签到: 1 天

    [LV.Master]测试大本营

    4#
    发表于 2022-4-12 13:36:07 | 只看该作者
    没连上?
    回复

    使用道具 举报

    本版积分规则

    关闭

    站长推荐上一条 /1 下一条

    小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

    GMT+8, 2024-11-25 07:45 , Processed in 0.062254 second(s), 21 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

    快速回复 返回顶部 返回列表