-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
48 lines (39 loc) · 1.88 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from bs4 import BeautifulSoup
import requests
from selenium import webdriver
import time
FORM_URL = "https://docs.google.com/forms/d/e/1FAIpQLSfD3DaZZV40IilKxFz1-UhuK45zRzw4RZPlcL7AIlCUfbGWNQ/viewform?usp=sf_link"
SPAREROOM = "https://www.spareroom.co.uk/flatshare/?search_id=1066887200&"
response = requests.get(SPAREROOM)
spareroom_webpage = response.text
soup = BeautifulSoup(spareroom_webpage, "html.parser")
listings = soup.find_all(name="article", class_="panel-listing-result")
addresses = []
prices = []
links = []
for listing in listings:
address = listing.find(name="span", class_="listingLocation").text
addresses.append(address)
price = listing.find(name="strong", class_="listingPrice").text
prices.append(price)
link = listing.find("a", href=True)["href"]
links.append(link)
print(addresses)
print(prices)
print(links)
number_of_listings = len(prices)
chrome_driver_path = "C:/Development/chromedriver.exe"
driver = webdriver.Chrome(executable_path=chrome_driver_path)
#new_form_button = driver.find_element_by_xpath("/html/body/div[1]/div[2]/div[1]/div/div[4]/a")
for i in range(0,number_of_listings):
driver.get(FORM_URL)
address_input = driver.find_element_by_xpath("//*[@id='mG61Hd']/div[2]/div/div[2]/div[1]/div/div/div[2]/div/div[1]/div/div[1]/input")
price_input = driver.find_element_by_xpath("//*[@id='mG61Hd']/div[2]/div/div[2]/div[2]/div/div/div[2]/div/div[1]/div/div[1]/input")
link_input = driver.find_element_by_xpath("//*[@id='mG61Hd']/div[2]/div/div[2]/div[3]/div/div/div[2]/div/div[1]/div/div[1]/input")
submit_button = driver.find_element_by_xpath("//*[@id='mG61Hd']/div[2]/div/div[3]/div[1]/div[1]/div/span/span")
time.sleep(2)
address_input.send_keys(addresses[i])
price_input.send_keys(prices[i])
link_input.send_keys(links[i])
submit_button.click()
time.sleep(2)