from selenium import webdriver
import time
driver = webdriver.Chrome()
driver.set_window_size(1000,1000) #控制視窗大小
driver.get('https://comicbus.live/online/manga_9199.html?ch=8005')
time.sleep(1)
from bs4 import BeautifulSoup
import requests
soup=BeautifulSoup(driver.page_source,'lxml')
pagenum=int(soup.select_one('#pagenum').text.split('/')[1].strip('頁'))
for i in range(pagenum):
    soup=BeautifulSoup(driver.page_source,'lxml')
    img_url='https:'+soup.select_one('#TheImg').get('src')
    res=requests.get(img_url)
    with open('{}.jpg'.format(i+1),'wb')as f:
        f.write(res.content)
                                   
    nextpage=driver.find_element_by_id('next')
    nextpage.click()
 

阿亮 發表在 痞客邦 留言(0) 人氣()

import numpy as np
from sklearn.linear_model import LinearRegression
import matplotlib.pyplot as plt
 

阿亮 發表在 痞客邦 留言(0) 人氣()

pip install opencv--python
 

阿亮 發表在 痞客邦 留言(0) 人氣()

import pyautogui
import time
time.sleep(2)
#點擊一次編輯器(在任意可填寫的空白處)
pyautogui.click(button="left")
#輸入 I Like Python
pyautogui.typewrite("I Like Python")
#空行後每0.25秒輸入一個字
pyautogui.typewrite("\nI like python too.",0.25)
#輸入 good 然後將g改為大寫後跳至最後加上句號
pyautogui.typewrite(['enter','g','o','o','d','left','left','left','backspace','G','end','.'],0.25)

阿亮 發表在 痞客邦 留言(0) 人氣()

介面.png

 
import time
#系統準備時間
time.sleep(2)

阿亮 發表在 痞客邦 留言(0) 人氣()

import pyautogui
#屏幕大小
size=pyautogui.size()
print(size)

阿亮 發表在 痞客邦 留言(0) 人氣()

import requests
from bs4 import BeautifulSoup
res=requests.get('https://www.ptt.cc/bbs/joke/index.html')
soup=BeautifulSoup(res.text,'lxml')

阿亮 發表在 痞客邦 留言(0) 人氣()

requests.get之後 若遇到目前無法找到頁面
F12>Documents >Headers>Requests Headers送請求時的表投 >User-Agent #偽裝代理服務

阿亮 發表在 痞客邦 留言(0) 人氣()

import requests
res=requests.get("url",verify=False) #遇到SSLError 可以用verify繞過憑證檢查

阿亮 發表在 痞客邦 留言(0) 人氣()

anaconda安裝用Selenium
主要是因為爬蟲沒辦法直接看到JS的渲染

阿亮 發表在 痞客邦 留言(0) 人氣()

-------------------------------------------------------------------------------------------------------------------顯示兩張圖figure
x=np.linspace(-1,1,50)座標-1到1間有五十個點
y1=2*x+1
y2=x**2
plt.figure()第一張圖
plt.plot(x,y1)將xy1展現出來
plt.figure(num=3,figsize=(8,5)) 第二張圖改變figure編號與長8寬5
plt.plot(x,y2)
plt.plot(x,y1,color='red',linewidth=1.0,linestyle='--')顏色,線的寬度,線的種類(虛線)
plt.show把plt.plot秀出來
plt.xlim((-1,2))x座標頭尾極限
plt.ylim((-2,3))Y座標頭尾極限
plt.xlabel('I am X')X座標的名稱
plt.ylabel('I am Y')Y座標的名稱
new_ticks=np.linspace(-1,2,5)-1到2分五等分
plt.xticks(new_ticks)X座標直變成這五等分的數字(-1,-025,0.5,1.25,2)
plt.yticks([-2,-1.8,-1,1.22,3,], 將Y軸該值對應該文字
[r'$really\ bad$',r'$bad$','normal','good','really good']) r'$英文\ 字$'改變字體空格要反斜線
ax=plt.gca() gca=get current axis 表示前面那些圖
ax.spines['right'].set_color('none') 讓右邊邊界顏色消失
ax.spines['top'].set_color('none') = 上面 = = = = = =
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
ax.spines['bottom'].set_position(('data', -1)) 以-1為座標移動底邊界
ax.spines['left'].set_position(('data',0)) 以0為座標移動左邊界
x0=1
y0=2*x0+1
plt.scatter(x0,y0,s=50,color='b') 顯示點在圖上的位置 (x座標,y座標,size=?,color=?)
plt.plot([x0,x0],[y0,0],'k--',lw=2.5) ([x0到x0],[y0到y],k顏色黑色 --為虛線的style, lw=線的寬度)
plt.show()

阿亮 發表在 痞客邦 留言(0) 人氣()

import matplotlib.pyplot as plt
data = pd.DataFrame(np.random.randn(1000, 5), 顯示五行數字columns是ABCDE 5個英文字就要數字5
index=np.arange(1000),
columns=list("ABCDE"))
data=data.cumsum()數據累加
print(data.head(6)) 輸出前六列數據
data.plot()畫成圖表
plt.show() 意義不明
ax=data.plot.scatter(x='A',y='B',color='DarkBlue',label='Class 1') 點狀圖
data.plot.scatter(x='A',y='C',color='DarkRed',label='Class 2',ax=ax) ax=ax讓兩張圖數據合併在一張圖

阿亮 發表在 痞客邦 留言(0) 人氣()

1 2 3
Blog Stats
⚠️

成人內容提醒

本部落格內容僅限年滿十八歲者瀏覽。
若您未滿十八歲,請立即離開。

已滿十八歲者,亦請勿將內容提供給未成年人士。