(Python,Selenium Chromedriver)通过txt文件中的多个URL循环,以验证实时网页上的每个脚本标记
我有一个txt文件,其中有一个URL列表(sitemap.txt),我想使用该列表自动执行一个脚本,该脚本遍历每个URL,以验证元素(脚本标记)是否存在。最好的方法是什么(Python,Selenium Chromedriver)通过txt文件中的多个URL循环,以验证实时网页上的每个脚本标记,python,selenium,selenium-webdriver,automation,selenium-chromedriver,Python,Selenium,Selenium Webdriver,Automation,Selenium Chromedriver,我有一个txt文件,其中有一个URL列表(sitemap.txt),我想使用该列表自动执行一个脚本,该脚本遍历每个URL,以验证元素(脚本标记)是否存在。最好的方法是什么 from selenium import webdriver #-*- coding: utf-8 -*- import re import urlparse def findnth(haystack, needle, n): parts= haystack.split(needle, n+1) if len
from selenium import webdriver
#-*- coding: utf-8 -*-
import re
import urlparse
def findnth(haystack, needle, n):
parts= haystack.split(needle, n+1)
if len(parts)<=n+1:
return -1
return len(haystack)-len(parts[-1])-len(needle)
with open("sitemap.txt") as file:
for line in file:
substring = "url"
if substring in line:
start = line.find('h')
end = findnth(line, "<", 2)
print(line[start:end])
# #path = urlparse(line)
# urls = re.findall('https?://(?:[-\\w.]|(?:%[\\da-fA-F]{2}))+', line)
# #print(line)
# line.find('h')
# start = line.find('h')
# end = line.rfind('/')
# #print(line[, start[, end]])
# print(line)
for i in line:
driver = webdriver.Chrome()
driver.get(i)
source = driver.find_element_by_xpath("//script[@src='/scripts/file.js']");
从selenium导入webdriver
#-*-编码:utf-8-*-
进口稀土
导入URL解析
def findnth(干草堆、打捆针、北):
零件=干草堆。分开(针,n+1)
if len(零件)