import requests import string import re from bs4 import BeautifulSoup import openpyxl from openpyxl import load_workbook import argparse import os def dir_path(path): if os.path.isdir(path): return path else: raise argparse.ArgumentTypeError(f"readable_dir:{path} is not a valid path") parser = argparse.ArgumentParser() parser.add_argument("-f",type=str,default='redbook.xlsm') parser.add_argument("-w",type=str,default='Sheet1') parser.add_argument("-u") parser.add_argument("-r",type=str,default='R961893') args = parser.parse_args() print(args) # Making a GET request uri = 'https://www.redweek.com/posting/' + str(args.r) #uri = 'https://www.redweek.com/posting/' + str(args.r) r = requests.get(uri) # Parsing the HTML soup = BeautifulSoup(r.content, 'html.parser') w = soup.find(class_='total__price') x = soup.find('h2', class_='price-value mb-1') z = soup.find(class_='posting-main-price') v = soup.find(class_='posting-feat-unit-view') y = soup.find(class_='posting-main-title') u = soup.find(class_='posting-feat-sleep-bedrooms') u1 = soup.find(class_='posting-feat-sleep-guests') u2 = soup.find(class_='posting-feat-sleep-beds') all_links= soup.findAll('a') #from lxml import etree #dom = etree.HTML(str(soup)) #PropURL=(dom.xpath('//*[@id="main-content"]/div[2]/div/div[1]/div[1]/section/div[4]/header/h1/a')[0].text)# //*[@id="main-content"]/div[2]/div/div[1]/div[1]/section/div[4]/header/h1/a #PropURLtext=PropURL #PropURL = re.sub('<.*?>','',PropURL) #PropURL = re.sub('(^.*? (?=<)<)','',PropURL) #PropURL = all_links[65] PropertyName = str(y.text).strip() PricePerNight = str(x.text).strip() ResortView = str(v.text).strip() ResortView = ResortView.replace("View: ", "") Bedrooms = str(u.text).strip() Bedrooms = Bedrooms.replace("\n"," ") SearchBedrooms = re.sub('\D', '', Bedrooms) Sleeps = str(u1.text).strip() Sleeps = Sleeps.replace("\n"," ") SearchSleeps = re.sub('\D', '', Sleeps) SearchView = re.sub(" ",'%20',ResortView) LOS = '' BedDetails = str(u2.text).strip() BedDetails = BedDetails.replace("\n"," ") CheckIn = "" URL = str(y).strip() URL = URL.replace("\n", "") URL = URL.replace("