Issue
import os
from bs4 import BeautifulSoup as bs
from datetime import date, timedelta
import requests
import pprint
import re
import pyperclip
#We need from 2017.11.1 to 2023.10.26
#The format for this particular html is 'mmddyy'
def daterange(start_date, end_date):
for n in range(int((end_date - start_date).days)):
yield start_date + timedelta(n)
start_date = date(2017,11,1)
end_date = date(2023,10,27)
archive_date_range_list = []
for single_date in daterange(start_date, end_date):
x = (single_date.strftime("%m%d%y"))
archive_date_range_list.append(x)
new_list_dates = ','.join([x for x in archive_date_range_list])
new_list_dates = new_list_dates.split(",")
new_list_dates
#Little River Outfitters website URL with the archive date variable
#we need the format URL1+"date"+URL2
URL1 = [r'https://littleriveroutfitters.com/WEBSITE-2008/pages/fishing/']
URL2 = [r'.htm']
#loop to configure the particular website
website_dates_list = []
for i in new_list_dates:
x1 = URL1,i,URL2
website_dates_list.append(x1)
website_dates_list
So I have the list :
['https://littleriveroutfitters.com/WEBSITE-2008/pages/fishing/', 102623,'.htm']
however, I need to join them all to make:
['https://littleriveroutfitters.com/WEBSITE-2008/pages/fishing/102623.htm']
I might be confusing myself, but I have tried .join and I am messing it up more.
I have tried:
''.join(str(website_dates_list))
I was anticipating:
['https://littleriveroutfitters.com/WEBSITE-2008/pages/fishing/102623.htm']
Yet I received:
['https://littleriveroutfitters.com/WEBSITE-2008/pages/fishing/'...102523,102623...and so on'.htm']
Solution
IIUC, is this what you want?
pages = range(102623, 102630, 1)
baseurl = 'https://littleriveroutfitters.com/WEBSITE-2008/pages/fishing/'
my_url_list= [''.join(map(str, [baseurl, p, '.htm'])) for p in pages]
my_url_list
Output:
['https://littleriveroutfitters.com/WEBSITE-2008/pages/fishing/102623.htm',
'https://littleriveroutfitters.com/WEBSITE-2008/pages/fishing/102624.htm',
'https://littleriveroutfitters.com/WEBSITE-2008/pages/fishing/102625.htm',
'https://littleriveroutfitters.com/WEBSITE-2008/pages/fishing/102626.htm',
'https://littleriveroutfitters.com/WEBSITE-2008/pages/fishing/102627.htm',
'https://littleriveroutfitters.com/WEBSITE-2008/pages/fishing/102628.htm',
'https://littleriveroutfitters.com/WEBSITE-2008/pages/fishing/102629.htm']
Answered By - Scott Boston
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.