honey234 commited on
Commit
2b3e1c6
·
1 Parent(s): 705801c
.gitignore CHANGED
@@ -1 +1,54 @@
1
- *.env
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # Virtual environment
7
+ venv/
8
+ ENV/
9
+ env/
10
+ .venv/
11
+ .ENV/
12
+
13
+ # Jupyter Notebook checkpoints
14
+ .ipynb_checkpoints
15
+
16
+ # VS Code files
17
+ .vscode/
18
+
19
+ # PyCharm files
20
+ .idea/
21
+
22
+ # Distribution / Packaging
23
+ build/
24
+ dist/
25
+ cache/
26
+ .wdm/
27
+ Lib/
28
+ Include/
29
+ Scripts/
30
+ *.egg-info/
31
+ *.egg
32
+ *.whl
33
+
34
+ # Logs and debug files
35
+ *.log
36
+
37
+ # Test results
38
+ *.out
39
+ *.coverage
40
+ .coverage.*
41
+
42
+ # Environment variables and settings
43
+ .env
44
+ *.env
45
+
46
+ pip-log.txt
47
+ pip-delete-this-directory.txt
48
+
49
+ # macOS files
50
+ .DS_Store
51
+
52
+ # Windows files
53
+ Thumbs.db
54
+ /databases/service-account.json
Dockerfile ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use the official Python image as the base image
2
+ FROM python:3.10-slim
3
+
4
+ # Install dependencies for Selenium and Chrome
5
+ RUN apt-get update && apt-get install -y \
6
+ wget \
7
+ unzip \
8
+ curl \
9
+ gnupg \
10
+ libnss3 \
11
+ libgconf-2-4 \
12
+ libxi6 \
13
+ libxcursor1 \
14
+ libxrandr2 \
15
+ libxss1 \
16
+ libxtst6 \
17
+ fonts-liberation \
18
+ xdg-utils \
19
+ libatk-bridge2.0-0 \
20
+ libgtk-3-0 \
21
+ --no-install-recommends && \
22
+ apt-get clean && \
23
+ rm -rf /var/lib/apt/lists/*
24
+
25
+ RUN apt-get update && apt-get install -y wget unzip && \
26
+ wget https://dl.google.com/Linux/direct/google-chrome-stable_current_amd64.deb && \
27
+ apt install -y ./google-chrome-stable_current_amd64.deb && \
28
+ rm google-chrome-stable_current_amd64.deb && \
29
+ apt-get clean
30
+
31
+ RUN which google-chrome
32
+
33
+ # Update the package list and install wget, unzip, and Firefox
34
+ # RUN apt-get update && apt-get install -y wget unzip \
35
+ # && apt-get install -y firefox-esr \
36
+ # && apt-get clean
37
+ RUN useradd -m -u 1000 user
38
+ USER user
39
+ ENV HOME=/home/user \
40
+ PATH=/home/user/.local/bin:$PATH
41
+
42
+ WORKDIR $HOME/app
43
+ # WORKDIR /app
44
+
45
+ COPY --chown=user . $HOME/app
46
+ # COPY . /app
47
+ # Install Python dependencies
48
+ RUN pip install --no-cache-dir -r requirements.txt
49
+
50
+ # Run the Selenium script
51
+ # CMD ["gunicorn", "-b", "0.0.0.0:7860","app:app"]
52
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
README.md CHANGED
@@ -1,10 +1,12 @@
1
  ---
2
- title: NextanalyticsScraper1.0
3
- emoji: 👁
4
- colorFrom: gray
5
- colorTo: green
6
  sdk: docker
7
  pinned: false
 
 
8
  ---
9
 
10
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: NextAnalyticsScraping
3
+ emoji: 📚
4
+ colorFrom: pink
5
+ colorTo: yellow
6
  sdk: docker
7
  pinned: false
8
+ license: apache-2.0
9
+ short_description: scraping test hosting
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,267 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import random
3
+ import time
4
+ import pandas as pd
5
+ from fastapi import FastAPI, HTTPException
6
+ from seleniumwire import webdriver
7
+ from selenium.webdriver.chrome.service import Service
8
+ from selenium.webdriver.common.action_chains import ActionChains
9
+ from selenium.webdriver.chrome.options import Options
10
+ from webdriver_manager.chrome import ChromeDriverManager
11
+ from webdriver_manager.core.driver_cache import DriverCacheManager
12
+ from selenium.webdriver.common.by import By
13
+ from fake_headers import Headers
14
+ from fastapi.middleware.cors import CORSMiddleware
15
+ import logging
16
+ from selenium_driverless import webdriver as webdriverless
17
+
18
+ proxy_username="ockzoweb"
19
+ proxy_password="23wxmulibzuq"
20
+ proxy_address="198.23.239.134"
21
+ proxy_port="6540"
22
+
23
+ proxy_url=f"http://{proxy_username}:{proxy_password}@{proxy_address}:{proxy_port}"
24
+ seleniumwire_options = {
25
+ "proxy": {
26
+ "http": proxy_url,
27
+ "https": proxy_url,
28
+ }
29
+ }
30
+ # Initialize FastAPI
31
+ app = FastAPI(
32
+ debug=True,
33
+ title="NextAnalytics Server",
34
+ consumes=["application/x-www-form-urlencoded", "multipart/form-data"],
35
+ docs_url='/swagger'
36
+ )
37
+
38
+ # Configure CORS
39
+ app.add_middleware(
40
+ CORSMiddleware,
41
+ allow_origins=["*"],
42
+ allow_credentials=True,
43
+ allow_methods=["*"],
44
+ allow_headers=["*"],
45
+ )
46
+
47
+ # Setup ChromeDriver and Selenium
48
+ # custom_wdm_cache = os.path.join(os.getcwd(), 'custom_wdm_cache')
49
+ # os.environ['WDM_LOCAL'] = custom_wdm_cache
50
+
51
+ # Setup logging
52
+ logging.basicConfig(level=logging.INFO)
53
+
54
+ def setup_chromedriver():
55
+ logging.info("Setting up ChromeDriver...")
56
+ # custom_wdm_cache = os.path.join(os.getcwd(), 'custom_wdm_cache')
57
+ # os.environ['WDM_LOCAL'] = custom_wdm_cache
58
+ # cache_manager = DriverCacheManager(custom_wdm_cache)
59
+ # os.chmod(custom_wdm_cache, 0o755) # Ensure proper permissions
60
+ # path = ChromeDriverManager(cache_manager=cache_manager).install()
61
+ path = ChromeDriverManager().install()
62
+ os.chmod(path, 0o755) # Ensure ChromeDriver is executable
63
+ logging.info(f"ChromeDriver path: {path}")
64
+ return path
65
+
66
+ # Setup headless Chrome options
67
+ # Define a custom user agent
68
+ # my_user_agent = "Mozilla/5.0 (X11; Linux x86_64; rv:92.0) Gecko/20100101 Firefox/92.0"
69
+
70
+ my_user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36"
71
+
72
+ # capabilities = webdriver.DesiredCapabilities.FIREFOX
73
+ # proxy = None
74
+ browser_option = Options()
75
+ browser_option.add_argument("--headless") # Running in headless mode (no GUI)
76
+ browser_option.add_argument("--no-sandbox")
77
+ browser_option.add_argument("--disable-dev-shm-usage")
78
+ browser_option.add_argument("--ignore-certificate-errors")
79
+ # browser_option.binary_location = '/usr/bin/firefox'
80
+ # browser_option.binary_location = r'C:\Users\HP\.cache\selenium\firefox\win64\133.0\firefox.exe'
81
+ # browser_option.add_argument("--disable-gpu")
82
+ # browser_option.add_argument("--log-level=3")
83
+ # browser_option.add_argument("--disable-notifications")
84
+ # browser_option.add_argument("--disable-popup-blocking")
85
+ browser_option.add_argument(f"--user-agent={my_user_agent}")
86
+
87
+ # if proxy:
88
+ # browser_option.add_argument(f"--proxy-server={proxy}")
89
+
90
+
91
+ # Setup WebDriver
92
+ driver_path = setup_chromedriver()
93
+ service = Service(executable_path=driver_path)
94
+ driver = webdriver.Chrome(service=service, options=browser_option,)
95
+ # actions = ActionChains(driver)
96
+
97
+ def getSearchPostData(search_keyword, index, name="", forCompetitorAnalysis=False):
98
+ # Navigate to the search results page
99
+ url = f'https://www.reddit.com/search/?q={search_keyword}'
100
+ driver.get(url)
101
+ time.sleep(3) # Consider using WebDriverWait instead of sleep for better reliability
102
+ logging.info("Navigated to search page.")
103
+
104
+ posts_data = []
105
+ list_length = 0 # posts count
106
+ try:
107
+ if forCompetitorAnalysis:
108
+ driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
109
+ time.sleep(5)
110
+ post_cards = driver.find_elements(By.CSS_SELECTOR, 'a[data-testid="post-title-text"]')
111
+ post_cards_1 = driver.find_elements(By.CSS_SELECTOR, 'div[data-testid="search-counter-row"]')
112
+ post_cards_2 = driver.find_elements(By.CSS_SELECTOR, 'faceplate-timeago')
113
+ logging.info(f"Found {len(post_cards)} post cards.")
114
+
115
+ idx = list_length
116
+ for card in post_cards_1:
117
+ try:
118
+ votes_count = card.find_element(By.XPATH, './/faceplate-number').text
119
+ comments_count = card.find_element(By.XPATH,
120
+ './/span[contains(text(), "comment") or contains(text(), "comments")]/preceding-sibling::faceplate-number'
121
+ ).text
122
+ posts_data.append({
123
+ "index": idx,
124
+ "comment_count": comments_count,
125
+ "votes_count": votes_count
126
+ })
127
+ idx += 1
128
+ except Exception as e:
129
+ logging.error(f"Error processing post_card_1: {e}")
130
+
131
+ idx = list_length
132
+ for card in post_cards:
133
+ try:
134
+ url = card.get_attribute("href")
135
+ title = card.text
136
+ posts_data[idx]["title"] = title
137
+ posts_data[idx]["url"] = url
138
+ idx += 1
139
+ except Exception as e:
140
+ logging.error(f"Error processing post_cards: {e}")
141
+
142
+ idx = list_length
143
+ for card in post_cards_2:
144
+ try:
145
+ time_element = card.find_element(By.XPATH, './time')
146
+ post_time = time_element.get_attribute('datetime')
147
+ posts_data[idx]["time"] = post_time
148
+ idx += 1
149
+ except Exception as e:
150
+ logging.error(f"Error processing post_cards_2: {e}")
151
+ except Exception as e:
152
+ logging.error(f"Error in scrolling or extracting data: {e}")
153
+
154
+ df = pd.DataFrame(posts_data)
155
+ df.to_csv(f'posts_data_{index}.csv', index=False)
156
+ logging.info(f"Data saved to posts_data_{index}.csv")
157
+ return df
158
+
159
+ def get_webpage_title(url: str) -> str:
160
+ try:
161
+ getSearchPostData(search_keyword="migraine", index=0)
162
+ url="https://www.reddit.com"
163
+ driver.get(url)
164
+ title = driver.title
165
+ logging.info(f"Page title: {title}")
166
+ return title
167
+ except Exception as e:
168
+ logging.error(f"Error fetching webpage title: {e}")
169
+ return str(e)
170
+
171
+ @app.get("/")
172
+ async def home():
173
+ return {"message": "Hello"}
174
+
175
+ @app.get("/get-title/")
176
+ async def fetch_title(url: str):
177
+ """
178
+ Fetch the title of a webpage by URL.
179
+ Example: /get-title/?url=https://www.reddit.com
180
+ """
181
+ try:
182
+ title = get_webpage_title(url)
183
+ return {"url": url, "title": title}
184
+ except Exception as e:
185
+ raise HTTPException(status_code=500, detail=str(e))
186
+ # @app.get("/get-reddit/")
187
+ # async def getReddit(url: str):
188
+ # """
189
+ # Fetch the title of a webpage by URL.
190
+ # Example: /get-title/?url=https://www.reddit.com
191
+ # """
192
+ # try:
193
+ # options = webdriverless.ChromeOptions()
194
+ # driver_agent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36"
195
+
196
+ # options.add_argument("--headless") # Running in headless mode (no GUI)
197
+ # options.add_argument("--no-sandbox")
198
+ # options.add_argument("--disable-dev-shm-usage")
199
+ # options.add_argument("--ignore-certificate-errors")
200
+ # options.add_argument(f"--user-agent={driver_agent}")
201
+
202
+ # title="Notitle"
203
+ # async with webdriverless.Chrome(options=options) as driver:
204
+ # await driver.get('https://www.reddit.com')
205
+ # time.sleep(3)
206
+
207
+ # title = await driver.title
208
+ # url = await driver.current_url
209
+ # source = await driver.page_source
210
+ # print(title)
211
+ # return {"url": url, "title": title}
212
+ # return {"url": url, "title": title}
213
+ # except Exception as e:
214
+ # raise HTTPException(status_code=500, detail=str(e))
215
+
216
+ # Run the app
217
+ # if __name__ == "__main__":
218
+ # import uvicorn
219
+ # uvicorn.run(app, host="127.0.0.1", port=7860)
220
+
221
+ # from selenium import webdriver
222
+ # from flask import Flask, request
223
+ # from selenium.webdriver.chrome.service import Service
224
+ # from webdriver_manager.chrome import ChromeDriverManager
225
+ # from selenium.webdriver.common.by import By
226
+ # from selenium.webdriver.common.proxy import Proxy, ProxyType
227
+ # app = Flask(__name__)
228
+
229
+
230
+ # def download_selenium():
231
+ # prox = Proxy()
232
+ # prox.proxy_type = ProxyType.MANUAL
233
+ # prox.http_proxy = "ip_addr:port"
234
+ # prox.socks_proxy = "ip_addr:port"
235
+ # prox.ssl_proxy = "ip_addr:port"
236
+ # chrome_options = webdriver.ChromeOptions()
237
+ # driver_agent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36"
238
+ # capabilities = webdriver.DesiredCapabilities.CHROME
239
+ # prox.to_capabilities(capabilities)
240
+ # chrome_options.add_argument("--headless=new")
241
+ # # chrome_options.add_argument(f"--proxy-server={proxy}")
242
+ # chrome_options.add_argument("--no-sandbox")
243
+ # chrome_options.add_argument("--disable-dev-shm-usage")
244
+ # # chrome_options.add_argument("--ignore-certificate-errors")
245
+ # # chrome_options.add_argument("--disable-gpu")
246
+ # # chrome_options.add_argument("--log-level=3")
247
+ # # chrome_options.add_argument("--disable-notifications")
248
+ # # chrome_options.add_argument("--disable-popup-blocking")
249
+ # prefs = {"profile.managed_default_content_settings.images": 2}
250
+ # # chrome_options.add_experimental_option("prefs", prefs)
251
+ # chrome_options.add_argument(f"--user-agent={driver_agent}")
252
+ # driver = webdriver.Chrome(service=Service(ChromeDriverManager().install(),desired_capabilities=capabilities), options=chrome_options)
253
+ # driver.get("https://reddit.com")
254
+ # title = driver.title
255
+ # # language = driver.find_element(By.XPATH, "//div[@id='SIvCob']").text
256
+ # data = {'Page Title': title}
257
+ # return data
258
+
259
+
260
+ # @app.route('/', methods = ['GET','POST'])
261
+ # def home():
262
+ # if (request.method == 'GET'):
263
+ # return download_selenium()
264
+
265
+
266
+ # if __name__ == "__main__":
267
+ # app.run(debug=True, port=3000)
custom_wdm_cache/.gitkeep ADDED
File without changes
posts_data_0.csv ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ index,comment_count,votes_count,title,url,time
2
+ 0,26,6,Migraine DBQ,https://www.reddit.com/r/VeteransBenefits/comments/1cogdv4/migraine_dbq/,2024-05-10T03:51:24.726Z
3
+ 1,84,651,A cool guide to migraine symptoms!,https://www.reddit.com/r/coolguides/comments/1f7wymg/a_cool_guide_to_migraine_symptoms/,2024-09-03T10:56:10.230Z
4
+ 2,321,141,What makes you sure it's a migraine?,https://www.reddit.com/r/migraine/comments/1cth4kw/what_makes_you_sure_its_a_migraine/,2024-05-16T16:33:05.274Z
5
+ 3,217,100,Biggest migraine life hacks?,https://www.reddit.com/r/migraine/comments/1902t0p/biggest_migraine_life_hacks/,2024-01-06T15:49:12.132Z
6
+ 4,112,40,What finally stopped your migraine?,https://www.reddit.com/r/migraine/comments/1e7wvsc/what_finally_stopped_your_migraine/,2024-07-20T14:27:22.529Z
7
+ 5,228,222,ELI5: What causes Migraines?,https://www.reddit.com/r/explainlikeimfive/comments/1e84z59/eli5_what_causes_migraines/,2024-07-20T20:35:12.699Z
8
+ 6,1K,2.9K,Most people use the word 'migraine' wrong.,https://www.reddit.com/r/unpopularopinion/comments/1884d1g/most_people_use_the_word_migraine_wrong/,2023-12-01T05:45:16.842Z
9
+ 7,236,1.9K,Wife’s migraines reduced by 90% and I feel like a jackass,https://www.reddit.com/r/migraine/comments/1g1dxw5/wifes_migraines_reduced_by_90_and_i_feel_like_a/,2024-10-11T16:31:11.670Z
10
+ 8,257,1.1K,It's just a migraine,https://www.reddit.com/r/Radiology/comments/1cisw7o/its_just_a_migraine/,2024-05-02T22:33:13.773Z
11
+ 9,239,660,"The cure for migraines! I've got it now, you can all stop searching! /s",https://www.reddit.com/r/migraine/comments/1ebkkff/the_cure_for_migraines_ive_got_it_now_you_can_all/,2024-07-25T03:09:38.426Z
12
+ 10,40,10,What are your migraine relief tricks?,https://www.reddit.com/r/AskReddit/comments/15oald2/what_are_your_migraine_relief_tricks/,2023-08-11T14:34:43.326Z
13
+ 11,400,1.7K,Some migraine symptoms you might not expect,https://www.reddit.com/r/migraine/comments/1e8zlkv/some_migraine_symptoms_you_might_not_expect/,2024-07-21T23:20:45.826Z
14
+ 12,158,3.1K,I painted this based on the visuals I get from migraines.,https://www.reddit.com/r/AbstractArt/comments/1gojgxz/i_painted_this_based_on_the_visuals_i_get_from/,2024-11-11T04:02:54.421Z
15
+ 13,185,698,migraine suffers are born with defective nervous systems,https://www.reddit.com/r/migraine/comments/1bs1g6c/migraine_suffers_are_born_with_defective_nervous/,2024-03-31T04:09:32.745Z
16
+ 14,911,25K,I’ve had constant migraines for the past week thanks to Matlab.,https://www.reddit.com/r/ProgrammerHumor/comments/xbmg98/ive_had_constant_migraines_for_the_past_week/,2022-09-11T16:10:36.852Z
17
+ 15,65,41,ELI5: what is the difference between a Headache vs a migraine?,https://www.reddit.com/r/explainlikeimfive/comments/1ccqoaj/eli5_what_is_the_difference_between_a_headache_vs/,2024-04-25T12:28:12.099Z
18
+ 16,243,6.5K,Need to share this. I got a migraine from laughing so hard.,https://www.reddit.com/r/BaldursGate3/comments/1butvvc/need_to_share_this_i_got_a_migraine_from_laughing/,2024-04-03T14:23:48.741Z
19
+ 17,54,6,What type of Migraine Logs does VA accept?,https://www.reddit.com/r/VeteransBenefits/comments/1fmdy2v/what_type_of_migraine_logs_does_va_accept/,2024-09-21T21:54:44.854Z
20
+ 18,231,1.9K,Raise your hand if you’re an American with a stress induced migraine today,https://www.reddit.com/r/migraine/comments/1gk64ce/raise_your_hand_if_youre_an_american_with_a/,2024-11-05T13:01:07.737Z
21
+ 19,240,316,Sign a migraine is coming,https://www.reddit.com/r/migraine/comments/1b90est/sign_a_migraine_is_coming/,2024-03-07T17:33:14.935Z
22
+ 20,1.1K,24K,TIL: Migraines are 3 times more common in women than in men.,https://www.reddit.com/r/todayilearned/comments/t0jzlf/til_migraines_are_3_times_more_common_in_women/,2022-02-24T20:03:31.456Z
23
+ 21,16,6,Migraine or MS?,https://www.reddit.com/r/MultipleSclerosis/comments/1fu5xnr/migraine_or_ms/,2024-10-02T02:31:44.292Z
24
+ 22,644,3.4K,This is the first time I’ve had someone tell me what I have isn’t a migraine. I mentioned having to grocery shop during a migraine and got this as a response.,https://www.reddit.com/r/migraine/comments/1780gdm/this_is_the_first_time_ive_had_someone_tell_me/,2023-10-14T22:12:03.962Z
25
+ 23,91,46,How do you manage your migraines?,https://www.reddit.com/r/POTS/comments/1duim0f/how_do_you_manage_your_migraines/,2024-07-03T16:27:50.806Z
26
+ 24,928,10K,10 minutes video call healthcare for $300 ...and just for migraine. Wow.,https://www.reddit.com/r/facepalm/comments/w6t020/10_minutes_video_call_healthcare_for_300_and_just/,2022-07-24T10:59:04.264Z
requirements.txt ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ flask==3.0.3
2
+ gunicorn
3
+ flask_cors
4
+ selenium==4.26.1
5
+ uvicorn
6
+ scalar_fastapi==1.0.3
7
+ requests
8
+ pandas
9
+ numpy
10
+ webdriver_manager==4.0.2
11
+ fake_headers
12
+ fastapi
13
+ selenium_driverless
14
+ asyncio
15
+ selenium-wire
16
+ blinker==1.7.0
17
+
18
+ # selenium==4.6.0
19
+ # requests==2.28.1
20
+ # webdriver_manager==3.8.4
21
+ # packaging==21.3
22
+ # flask-restful==0.3.9
23
+ # gunicorn==20.1.0
selenium_webapp-main/Dockerfile ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ARG PORT=443
2
+ FROM cypress/browsers:latest
3
+
4
+ RUN apt-get install python3 -y
5
+
6
+ RUN echo $(python3 -m site --user-base)
7
+
8
+ COPY requirements.txt .
9
+
10
+ ENV PATH /home/root/.local/bin:${PATH}
11
+
12
+ RUN apt-get update && apt-get install -y python3-pip && pip install -r requirements.txt
13
+
14
+ COPY . .
15
+
16
+ CMD uvicorn main:app --host 0.0.0.0 --port $PORT
selenium_webapp-main/requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ selenium==4.6.0
2
+ requests==2.28.1
3
+ webdriver_manager==3.8.4
4
+ packaging==21.3
5
+ flask-restful==0.3.9
6
+ gunicorn==20.1.0
selenium_webapp-main/selenium_webapp.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from selenium import webdriver
2
+ from flask import Flask, request
3
+ from selenium.webdriver.chrome.service import Service
4
+ from webdriver_manager.chrome import ChromeDriverManager
5
+ from selenium.webdriver.common.by import By
6
+
7
+ app = Flask(__name__)
8
+
9
+
10
+ def download_selenium():
11
+ chrome_options = webdriver.ChromeOptions()
12
+ chrome_options.add_argument("--headless")
13
+ chrome_options.add_argument("--no-sandbox")
14
+ chrome_options.add_argument("--disable-dev-shm-usage")
15
+ prefs = {"profile.managed_default_content_settings.images": 2}
16
+ chrome_options.add_experimental_option("prefs", prefs)
17
+ driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=chrome_options)
18
+ driver.get("https://google.com")
19
+ title = driver.title
20
+ language = driver.find_element(By.XPATH, "//div[@id='SIvCob']").text
21
+ data = {'Page Title': title, 'Language': language}
22
+ return data
23
+
24
+
25
+ @app.route('/', methods = ['GET','POST'])
26
+ def home():
27
+ if (request.method == 'GET'):
28
+ return download_selenium()
29
+
30
+
31
+ if __name__ == "__main__":
32
+ app.run(debug=True, port=3000)
test.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import time
2
+ from selenium_driverless import webdriver
3
+ import asyncio
4
+
5
+
6
+ async def main():
7
+ options = webdriver.ChromeOptions()
8
+ async with webdriver.Chrome(options=options) as driver:
9
+ await driver.get('https://www.reddit.com')
10
+ time.sleep(3)
11
+
12
+ title = await driver.title
13
+ url = await driver.current_url
14
+ source = await driver.page_source
15
+ print(title)
16
+
17
+
18
+ asyncio.run(main())