-
Notifications
You must be signed in to change notification settings - Fork 3
/
craigslist_posting_bot.py
128 lines (93 loc) · 4.36 KB
/
craigslist_posting_bot.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
import time
from selenium.webdriver.support.ui import WebDriverWait
import os.path
def find(browser):
add_images = browser.find_element_by_xpath('//input[@name="file"]')
if add_images:
return add_images
else:
return False
browser = webdriver.Chrome('/Applications/PythonBotClass/selenium_tutorial/chromedriver')
browser.get('https://post.craigslist.org/')
# Select Location
browser.find_element_by_class_name('ui-selectmenu-text').click()
browser.find_element_by_xpath('//li[@id="ui-id-28"]').click()
browser.find_element_by_xpath('//button[@name="go"]').click()
# Post Type Page
browser.find_element_by_xpath('//input[@name="id" and @value="ho"]').click()
# Category
browser.find_element_by_xpath('//input[@name="id" and @value="143"]').click()
# Main post page
title_area = browser.find_element_by_xpath('//input[@name="PostingTitle" and @id="PostingTitle"]')
title_area.send_keys('Amazing 5 bedroom lakefront home')
city = browser.find_element_by_xpath('//input[@name="GeographicArea" and @id="GeographicArea"]')
city.send_keys('Austin, TX')
postal_code = browser.find_element_by_xpath('//input[@name="postal" and @id="postal_code"]')
postal_code.send_keys(74324)
time.sleep(1)
# main text section
main_text = browser.find_element_by_xpath('//textarea[@name="PostingBody" and @id="PostingBody"]')
main_text.send_keys('Check out a video presentation of the property: https://youtu.be/Cnvft2EaY')
main_text.send_keys(Keys.ENTER)
main_text.send_keys(Keys.ENTER)
main_text.send_keys('This is a wonderful family home. Located 2 blocks from brand new High School, and 5 miles from Boysen State Park and Reservoir and Wind River Canyon (both have camping and fishing), this is a great place to live for a family of any age.')
main_text.send_keys(Keys.ENTER)
main_text.send_keys(Keys.ENTER)
main_text.send_keys("$450,000")
main_text.send_keys(Keys.ENTER)
main_text.send_keys(Keys.ENTER)
main_text.send_keys('1000 ft on highway')
main_text.send_keys(Keys.ENTER)
main_text.send_keys(Keys.ENTER)
main_text.send_keys("Please inquire at 307-800-1769")
# Price
price = browser.find_element_by_xpath('//input[@name="price"]')
price.send_keys(450_000)
sqft = browser.find_element_by_xpath('//input[@name="Sqft"]')
sqft.send_keys(6_200)
house_type = browser.find_element_by_xpath('//span[@id="ui-id-1-button"]').click()
actions = ActionChains(browser)
for x in range(4):
actions.send_keys(Keys.ARROW_DOWN)
actions.send_keys(Keys.ENTER).click()
actions.perform()
laundry = browser.find_element_by_xpath('//span[@id="ui-id-2-button"]').click()
browser.find_element_by_xpath('//li[@id="ui-id-24"]').click()
bedrooms = browser.find_element_by_xpath('//span[@id="Bedrooms-button"]').click()
browser.find_element_by_xpath('//li[@id="ui-id-28"]').click()
bathrooms = browser.find_element_by_xpath('//span[@id="ui-id-4-button"]').click()
browser.find_element_by_xpath('//li[@id="ui-id-40"]').click()
email = browser.find_element_by_xpath('//input[@name="FromEMail"]')
email.send_keys('[email protected]')
browser.find_element_by_xpath('//button[@name="go" and @value="continue"]').click()
# Find Location
street = browser.find_element_by_xpath('//input[@name="xstreet0" and @id="xstreet0"]')
street.send_keys('4104 Shimmering Cv')
city_location = browser.find_element_by_xpath('//input[@name="city" and @id="city"]')
city_location.send_keys('Austin')
find_location = browser.find_element_by_xpath('//button[@id="search_button"]').click()
time.sleep(1)
location_submit = browser.find_element_by_xpath('//button[@class="continue bigbutton"]').click()
# Send Pictures
browser.find_element_by_xpath('//a[@id="classic"]').click()
add_images = browser.find_element_by_xpath('//input[@name="file"]')
img = []
path = '/Applications/PythonBotClass/selenium_tutorial/random_house/'
valid_image = ['.jpg', '.gif', '.png', '.tga']
for f in os.listdir(path):
ext = os.path.splitext(f)[1]
if ext.lower() not in valid_image:
continue
print(f)
img.append(f'/random_house/{f}')
for i in sorted(img):
if add_images != False:
print(os.getcwd() + i)
add_images.send_keys(os.getcwd() + i)
add_images = WebDriverWait(browser, 3).until(find)
else:
continue
browser.find_element_by_xpath('//button[@value="Done with Images"]').click()