Question
[Python & Selenium Chromedriver] I have a txt file that has a list of URLs (sitemap.txt) and I want to use that list to automate
example:get url from txt file > url is opened through chrome browser > inspect webpage > validate https://j.6sc.co/6si.min.js is present> go to the next line of url > repeat validation
txt file looks like
https://zendesk.com
https://zendesk.com/service
CODE
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) return -1 return len(haystack)-len(parts[-1])-len(needle)
with open(\"sitemap.txt\") as file: for line in file: substring = \"https://essentials.zendesk.com/\" if substring in line: start = line.find('h') end = findnth(line, \"\",> print(line[start:end])
with open(sitemap.txt) as file:
for i in line: driver = webdriver.Chrome() driver.get(i) source = driver.find_element_by_xpath(\"//script[@src='https://j.6sc.co/6si.min.js']\");
This for loop code might be wrong
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started