简体   繁体   中英

How do I check if a URL will download a file using Selenium in Python?

I have to visit a list of URLs but I do not want to open those which will start a download.

for url in url_list:
   if (url will not start a download):
      driver.get(url)
      ..................
   else:
      continue

Does someone have a solution for this? thanks in advance for the answers

首先你可以得到 url 然后在 java 中使用 selenium 你可以在以下条件下:

(String)((JavascriptExecutor) driver).executeScript("return document.contentType;").equals("text/html");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM