Skip to content

Commit

Permalink
update X image and 2048
Browse files Browse the repository at this point in the history
  • Loading branch information
Edit-Mr committed Nov 11, 2023
1 parent af58097 commit 60d2c38
Show file tree
Hide file tree
Showing 9 changed files with 488 additions and 124 deletions.
File renamed without changes.
19 changes: 19 additions & 0 deletions dl/2048.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
from selenium.webdriver.common.by import By

# Open the 2048 game website using Selenium
driver = webdriver.Chrome()
driver.get("https://play2048.co/")
time.sleep(3)
while True:
driver.find_element(By.TAG_NAME, 'body').send_keys(Keys.ARROW_UP)
time.sleep(0.1)
driver.find_element(By.TAG_NAME, 'body').send_keys(Keys.ARROW_RIGHT)
time.sleep(0.1)
driver.find_element(By.TAG_NAME, 'body').send_keys(Keys.ARROW_DOWN)
time.sleep(0.1)
driver.find_element(By.TAG_NAME, 'body').send_keys(Keys.ARROW_LEFT)
time.sleep(0.1)

Binary file added dl/VSCodeUserSetup-x64-1.84.2.exe
Binary file not shown.
Binary file added dl/chromedriver.exe
Binary file not shown.
18 changes: 18 additions & 0 deletions dl/dlImg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

from selenium import webdriver
import urllib.request
import time
from selenium.webdriver.common.by import By
import requests

driver = webdriver.Chrome()
driver.get("https://twitter.com/cat_auras")
time.sleep(5)
images = driver.find_elements(By.TAG_NAME, 'img')
for i, image in enumerate(images):
print("正在下載第" + str(i) + "張圖片")
src = image.get_attribute('src')
response = requests.get(src, stream=True)
if response.status_code == 200:
with open(f'image{i}.png', 'wb') as out_file:
out_file.write(response.content)
Binary file added dl/python-3.12.0-amd64.exe
Binary file not shown.
29 changes: 29 additions & 0 deletions dl/twitter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from selenium import webdriver
import urllib.request
import time
from selenium.webdriver.common.by import By
import requests
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains

driver = webdriver.Chrome()

driver.get("https://twitter.com/cat_auras")

time.sleep(3)

for i in range(3):
actions = ActionChains(driver)
actions.send_keys(Keys.PAGE_DOWN).perform()
time.sleep(1)

time.sleep(3)

images = driver.find_elements(By.TAG_NAME, 'img')
for i, image in enumerate(images):
print("正在下載第" + str(i) + "張圖片")
src = image.get_attribute('src')
response = requests.get(src, stream=True)
if response.status_code == 200:
with open(f'image{i}.png', 'wb') as out_file:
out_file.write(response.content)
363 changes: 254 additions & 109 deletions index.html

Large diffs are not rendered by default.

183 changes: 168 additions & 15 deletions 簡報.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,27 @@ backgroundImage: url("https://raw.githubusercontent.com/SCAICT/112-OP/main/img/s
112中電會聯合迎新

---

## 記分板

| 組別 | 分數 |
|-----|-----|
| 組別1 | 分數1 |
| 組別2 | 分數2 |
| 組別3 | 分數3 |
| 組別4 | 分數4 |
| 組別5 | 分數5 |

---

# 資源

* [內網]()
* [g.scaict.org/112-OP](https://g.scaict.org/112-OP)
* [GitHub](https://github.com/SCAICT/112-OP)

---

<div class="em">

##### 關於我
Expand Down Expand Up @@ -148,6 +169,8 @@ for i in range(1, 6):
---
# 安裝VS Code

[官網](https://code.visualstudio.com/) | [內網](dl/VSCodeUserSetup-x64-1.84.2.exe)

---

<!-- _backgroundImage: #000 -->
Expand All @@ -160,6 +183,8 @@ for i in range(1, 6):

# 安裝python

[官網](https://www.python.org/) | [內網](dl/python-3.12.0-amd64.exe)

---

<!-- _backgroundImage: #000 -->
Expand Down Expand Up @@ -195,6 +220,17 @@ for i in range(1, 6):

---

**輸出**
```python
print("Hello world")
```
**輸入**
```python
x = input("給IG嗎")
```
---


## 變數

<div class=l>
Expand All @@ -212,17 +248,6 @@ for i in range(1, 6):
x = "我是變數"
```

---

**輸出**
```python
print("Hello world")
```
**輸入**
```python
x = input("給IG嗎")
```

---
## 實作時間
#### 題目:詢問IG帳號,並輸出
Expand All @@ -236,12 +261,14 @@ IG是 elvisdragonmao
---
## 解答

[下載](code/ig.py)

```python
ig = input("給IG嗎?")
print("我會追蹤")
print(ig)
```

```python
ig = input("給IG嗎? ")
print("我會追蹤", ig)
Expand Down Expand Up @@ -336,6 +363,8 @@ i_am_list = [] # 宣告一個變數叫i_am_list

## code

[下載](code/pencil.py)

```python
a = int(input())
print(a // 12 * 50 + a % 12 * 5)
Expand Down Expand Up @@ -420,11 +449,13 @@ for i in range(1,5):
print(i) # 會列出1 2
```

[範例下載](code/break.py)

---

## continue

強制跳出這過迴圈
強制跳出這過迴圈 [範例下載](code/continue.py)

```python
for i in range(1,5):
Expand All @@ -439,6 +470,7 @@ for i in range(1,5):
4
```


---

# 網頁原理
Expand Down Expand Up @@ -643,6 +675,8 @@ print(response) #看看他的HTML
---
### 試試看

[範例下載](code/requests.py)

```python
import requests
from bs4 import BeautifulSoup
Expand Down Expand Up @@ -700,6 +734,8 @@ print(wiki)

# 解答

[下載](code/wiki.py)

```python
import requests
from bs4 import BeautifulSoup
Expand Down Expand Up @@ -783,7 +819,9 @@ for td_tag in td_tag_list:

---

Full Code
## Full Code

[下載](code/龍津高中公告.py)

<!-- _backgroundImage: #000 -->

Expand Down Expand Up @@ -846,6 +884,8 @@ for i in range(len(titles_list)):

## 範例程式碼

[下載](code/台中高工公告.py)

```python
import requests

Expand Down Expand Up @@ -881,7 +921,120 @@ else:

---

# 來點有趣的

# 下載 Chrome Driver

[官網](https://chromedriver.chromium.org/downloads) | [內網](dl/chromedriver.exe)

---
<!-- _backgroundImage: #000 -->
# 2048

[2048網站](https://play2048.co/)上右下左一直重複

很爛但很刺激

[範例程式](dl/2048.py)

----

```python
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
from selenium.webdriver.common.by import By

# Open the 2048 game website using Selenium
driver = webdriver.Chrome()
driver.get("https://play2048.co/")
time.sleep(3)
while True:
driver.find_element(By.TAG_NAME, 'body').send_keys(Keys.ARROW_UP)
time.sleep(0.1)
driver.find_element(By.TAG_NAME, 'body').send_keys(Keys.ARROW_RIGHT)
time.sleep(0.1)
driver.find_element(By.TAG_NAME, 'body').send_keys(Keys.ARROW_DOWN)
time.sleep(0.1)
driver.find_element(By.TAG_NAME, 'body').send_keys(Keys.ARROW_LEFT)
time.sleep(0.1)
```
---

# 爬一些重要圖片

## X Image

[範例程式](dl/dlImg.py)

---

```python

from selenium import webdriver
import urllib.request
import time
from selenium.webdriver.common.by import By
import requests

driver = webdriver.Chrome()
driver.get("https://twitter.com/cat_auras")
time.sleep(5)
images = driver.find_elements(By.TAG_NAME, 'img')
for i, image in enumerate(images):
print("正在下載第" + str(i) + "張圖片")
src = image.get_attribute('src')
response = requests.get(src, stream=True)
if response.status_code == 200:
with open(f'image{i}.png', 'wb') as out_file:
out_file.write(response.content)
```

---
看的不夠

# 往下滾

[範例程式](dl/twitter.py)

---

```python

from selenium import webdriver
import urllib.request
import time
from selenium.webdriver.common.by import By
import requests
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains

driver = webdriver.Chrome()

driver.get("https://twitter.com/cat_auras")

time.sleep(3)

for i in range(3):
actions = ActionChains(driver)
actions.send_keys(Keys.PAGE_DOWN).perform()
time.sleep(1)

time.sleep(3)

images = driver.find_elements(By.TAG_NAME, 'img')
for i, image in enumerate(images):
print("正在下載第" + str(i) + "張圖片")
src = image.get_attribute('src')
response = requests.get(src, stream=True)
if response.status_code == 200:
with open(f'image{i}.png', 'wb') as out_file:
out_file.write(response.content)
```


---

# ~~來點有趣的~~
## **去低(~~~~)卡爬梗圖**

---
Expand Down

0 comments on commit 60d2c38

Please sign in to comment.