Ad

Breaking Up A Web-link And Using For Loop In Python

- 1 answer

I am writing a python script for crawling emails

from selenium import webdriver
import re

driver = webdriver.Chrome("C:/Users/Sam/Downloads/chromedriver_win32/chromedriver.exe")
driver.get('https://stuactonline.tamu.edu/app/organization/profile/public/id/1488')

doc = driver.page_source

emails = re.findall(r'[\w\.-][email protected][\w\.-]+',doc)

print(emails)

if you notice the end of the link is the number 1488. I am trying to break it up where I can have a for loop that loops from 50 to about 5000 because there are multiple emails I want to get from the different websites ended in numbers from 1000 to 5000

Ad

Answer

You can easily parametrize the url:

for i in range(1000, 5000):
    driver.get('https://stuactonline.tamu.edu/app/organization/profile/public/id/' + str(i))

    #Your stuff...
Ad
source: stackoverflow.com
Ad