diff --git a/CHANGELOG b/CHANGELOG index a15f865..4e8fa1b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -8,4 +8,4 @@ - New build. ## 0.0.1 -- First public release. +- First public release. \ No newline at end of file diff --git a/README.md b/README.md index 7abf106..935ff88 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ Default json code: "url":"", "":{ "operations":[ - {"type":"","code":"","arg_code":"[n]","opt":"","arg_data":"[n]","data":""} + {"type":"","code":"","arg_code":"[n]","opt":"","arg_data":"[n]","data":""} ] } } @@ -50,6 +50,7 @@ Help: # If you don't use the 'code' key, you must use the 'arg_code' key to enter data from your script. # If you don't use the 'data' key, you must use the 'arg_data' key to enter data from your script. # When using the 'put' option you must use 'data' or 'arg_data', Unlike the "click" option. +# When using the 'get' option you must use 'data' or 'arg_data', Unlike the "click" option, data=get_attribute(""). # 'arg_data' and 'arg_code' are numbers. # 'arg_data' and 'arg_code' are the order of the element to be inserted from the list. //Example: p1.run(,n0,n1,n2....n) # 'data' and 'code' for entering data like password or username from json file (this is a common option if the variables you want to use are static). @@ -62,6 +63,7 @@ Help: from imbot import * # Examples +# Example 1: # Open the website link: p1=imbot("github.json") @@ -85,8 +87,9 @@ p1.run("login",'') Lines=open('list.txt','r').readlines() # Strips the newline character -for i in range(len(Lines)): - repositorie=Lines[i].strip() +#for i in range(len(Lines)): +for i, Line in enumerate(Lines): + repositorie=Line.strip() # To the repositorie: p1.run("go2repositorie",repositorie)# repositorie=="arg_code":"0" //Bearing in mind that the order of the variable is 0 # make operations: @@ -96,6 +99,17 @@ for i in range(len(Lines)): # end p1.end() + +# Example 2: +# Open the website link: +p2=imbot("google.json") + +# Here, search for a movie poster in Google Images and get the link: +print(p2.run("search","Game.Of.Thrones.Conquest.And.Rebellion.2017")) +print(p2.run("search","DEJA.VU.2018")) + +# end +p2.end() ```

Screenshot:

@@ -109,6 +123,10 @@ p1.end()

Changelog History:

``` +## 0.1.3 [28-05-2022] + - Add Return 'get_attribute' as a list. + - Fix bugs. + ## 0.1.2 [10-03-2022] - Fix bugs. diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..df03cef --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,79 @@ +# docker build -t imbot . +# docker run -i -t imbot +# +FROM ubuntu +LABEL maintainer "Sean Pianka " + +## For chromedriver installation: curl/wget/libgconf/unzip +RUN apt-get update -y && apt-get install -y wget curl unzip libgconf-2-4 +## For project usage: python3/python3-pip/chromium/xvfb +RUN apt-get update -y && apt-get install -y xvfb python3 python3-pip + + +# install manually all the missing libraries +RUN apt-get install -y gconf-service libasound2 libatk1.0-0 libcairo2 libcups2 libfontconfig1 libgdk-pixbuf2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libxss1 fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils + +# install chrome +RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb +RUN dpkg -i google-chrome-stable_current_amd64.deb; apt-get -fy install + +# Download, unzip, and install chromedriver +RUN wget -O /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`/chromedriver_linux64.zip +RUN unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/ + +# Create directory for project name (ensure it does not conflict with default debian /opt/ directories). +WORKDIR /wrdir + +## Your python project dependencies +#RUN pip3 install selenium +## or install from dependencies.txt, comment above and uncomment below +#COPY requirements.txt . +#RUN pip3 install -r requirements.txt + + +## Copy over project/script (feel free to combine these if your project is a combination of both directories and top-level files) +### For projects which are modules +#COPY app/ . +## For projects which are single scripts +COPY ./examples /wrdir +COPY ./imbot /wrdir/imbot +COPY ./requirements.txt /wrdir/requirements.txt +COPY ./run.sh /wrdir/run.sh + +RUN pip install --no-cache-dir --upgrade -r /wrdir/requirements.txt + + +# Set display port and dbus env to avoid hanging +ENV DISPLAY=:99 +ENV DBUS_SESSION_BUS_ADDRESS=/dev/null + + +# Bash script to invoke xvfb, any preliminary commands, then invoke project +#CMD ["Xvfb",":99","-screen","0","640x480x8","-nolisten","tcp","&&","python3","examples.py"] +#COPY run.sh . +CMD /bin/bash run.sh + +# + + + + + + + + + + + + +#FROM python:3.9 + +#WORKDIR /wrdir + +#COPY ./examples /wrdir +#COPY ./imbot /wrdir/imbot +#COPY ./requirements.txt /wrdir/requirements.txt + +#RUN pip install --no-cache-dir --upgrade -r /wrdir/requirements.txt + +#CMD ["python", "examples.py"] \ No newline at end of file diff --git a/docker/run.sh b/docker/run.sh new file mode 100644 index 0000000..33a2fe2 --- /dev/null +++ b/docker/run.sh @@ -0,0 +1,4 @@ +# Reason for "-nolisten tcp", not documented within Xvfb manpages (for who knows what reason) +# https://superuser.com/questions/855019/make-xvfb-listen-only-on-local-ip +Xvfb :99 -screen 0 640x480x8 -nolisten tcp & +python3 examples.py \ No newline at end of file diff --git a/examples/examples.py b/examples/examples.py index f603d44..5b35aaa 100644 --- a/examples/examples.py +++ b/examples/examples.py @@ -4,7 +4,7 @@ "url":"", "":{ "operations":[ - {"type":"","code":"","arg_code":"[n]","opt":"","arg_data":"[n]","data":""} + {"type":"","code":"","arg_code":"[n]","opt":"","arg_data":"[n]","data":""} ] } } @@ -14,14 +14,17 @@ # If you don't use the 'code' key, you must use the 'arg_code' key to enter data from your script. # If you don't use the 'data' key, you must use the 'arg_data' key to enter data from your script. # When using the 'put' option you must use 'data' or 'arg_data', Unlike the "click" option. +# When using the 'get' option you must use 'data' or 'arg_data', Unlike the "click" option, data=get_attribute(""). # 'arg_data' and 'arg_code' are numbers. # 'arg_data' and 'arg_code' are the order of the element to be inserted from the list. //Example: p1.run(,n0,n1,n2....n) # 'data' and 'code' for entering data like password or username from json file (this is a common option if the variables you want to use are static). + """ from imbot import * # Examples +# Example 1: # Open the website link: p1=imbot("github.json") @@ -56,4 +59,15 @@ p1.run("go2home") # end -p1.end() \ No newline at end of file +p1.end() + +# Example 2: +# Open the website link: +p2=imbot("google.json") + +# Here, search for a movie poster in Google Images and get the link: +print(p2.run("search","Game.Of.Thrones.Conquest.And.Rebellion.2017")) +print(p2.run("search","DEJA.VU.2018")) + +# end +p2.end() diff --git a/examples/google.json b/examples/google.json new file mode 100644 index 0000000..259bcfa --- /dev/null +++ b/examples/google.json @@ -0,0 +1,13 @@ +{ + "url":"https://www.google.com/", + "search":{ + "operations":[ + {"type":"xpath","code":"/html/body/c-wiz/c-wiz/div/div[3]/div[2]/div/div[1]/form/div[1]/div[1]/c-wiz/div/a","opt":"click"}, + {"type":"xpath","code":"/html/body/div[1]/div[3]/form/div[1]/div[1]/div[1]/div/div[2]/input","opt":"put","arg_data":"0"}, + {"type":"name","code":"btnK","opt":"click"}, + {"type":"xpath","code":"/html/body/div[7]/div/div[4]/div/div[1]/div/div[1]/div/div[2]/a","opt":"click"}, + {"type":"xpath","code":"/html/body/div[2]/c-wiz/div[3]/div[1]/div/div[1]/div/div[1]/div[1]/span/div[1]/div[1]/div[1]/a[1]/div[1]/img","opt":"click"}, + {"type":"xpath","code":"/html/body/div[2]/c-wiz/div[3]/div[2]/div[3]/div/div/div[3]/div[2]/c-wiz/div/div[1]/div[1]/div[3]/div/a/img","opt":"get","data":"src"} + ] + } +} \ No newline at end of file diff --git a/imbot/__init__.py b/imbot/__init__.py index 8ae2f2b..77eedab 100644 --- a/imbot/__init__.py +++ b/imbot/__init__.py @@ -35,6 +35,7 @@ def __init__(self,json_data,sleep_time=2,url=""): def run(self,goto,*argm): operations=self.json_data[goto]['operations'] #for i in range(len(operations)): + get_list=[] for i, operation in enumerate(operations): try: # @@ -49,6 +50,9 @@ def run(self,goto,*argm): if operation['opt']=="click": do="click()" text=f"[✓] Clicking on element_by_{types} : '{code}'" + exec(f"self.driver.find_element_by_{types}('{code}').{do}") + hexor().c(text,"#299c52") + sleep(self.sleep_time) # elif operation['opt']=="put": # @@ -60,10 +64,26 @@ def run(self,goto,*argm): data=input(hexor(True).c("Data is empty : ","#ff0000")) do=f"send_keys('{data}')" text=f"[✓] Putting data to element_by_{types} : '{code}'" + exec(f"self.driver.find_element_by_{types}('{code}').{do}") + hexor().c(text,"#299c52") + sleep(self.sleep_time) # - exec(f"self.driver.find_element_by_{types}('{code}').{do}") - hexor().c(text,"#299c52") - sleep(self.sleep_time) + elif operation['opt']=="get": + do="" + text=f"[✓] Get data to element_by_{types} : '{code}'" + # + if "arg_data" in operation: + data=argm[int(operation['arg_data'])] + elif "data" in operation: + data=operation['data'] + else: + data=input(hexor(True).c("Data is empty : ","#ff0000")) + #xxx="hiii" + xxx=f"self.driver.find_element_by_{types}('{code}').get_attribute('{data}')" + hexor().c(text,"#299c52") + get_list.append(eval(xxx)) + sleep(self.sleep_time) + # except Exception as e: try: # @@ -83,6 +103,7 @@ def run(self,goto,*argm): pass finally: pass + return get_list #end: def end(self): self.driver.close() diff --git a/requirements.txt b/requirements.txt index 8145c41..a559c0f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ hexor asciitext -selenium \ No newline at end of file +selenium diff --git a/screenshot/screenshot_1.png b/screenshot/screenshot_1.png index 44b2796..4661882 100644 Binary files a/screenshot/screenshot_1.png and b/screenshot/screenshot_1.png differ diff --git a/setup.py b/setup.py index d502b39..64f8dcd 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ from setuptools import setup,find_packages setup( name="imbot", - version="0.1.2", + version="0.1.3", author="YasserBDJ96", author_email="yasser.bdj96@gmail.com", description='''imbot for making a bot to control any website.''', @@ -36,4 +36,4 @@ ], python_requires=">=3.x.x" ) -#}END. \ No newline at end of file +#}END. diff --git a/version.txt b/version.txt index 8294c18..b1e80bb 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -0.1.2 \ No newline at end of file +0.1.3