今天要把我們之前做的照片爬取丟到discord上面~~
driver.set_window_size(10000,30000)
link_count = 0
for title in all_titles:
url = link_list[link_count]
driver.get(url)
......
for index, link in enumerate(image_links):
if not os.path.exists("images"):
os.mkdir("images") # 建立資料夾
if not os.path.exists("images\\"+title.text):
os.mkdir("images\\"+title.text)
img = requests.get(link) # 下載圖片
with open("images\\" + title.text +'\\' + image_tags[index] + str(index) + ".jpg", "wb") as file: # 開啟資料夾及命名圖片檔
file.write(img.content) # 寫入圖片的二進位碼
link_count+=1
跟之前一樣把那些print都改成discord傳送訊息吧~
driver.set_window_size(10000,30000)
link_count = 0
for title in all_titles:
url = link_list[link_count]
driver.get(url)
close = driver.find_element(By.CSS_SELECTOR, 'a[class="bh-photo-grid-item bh-photo-grid-side-photo active-image "]')
close.click()
source = driver.page_source
soup = BeautifulSoup(source, "lxml")
body = soup.find("body")
imgs = body.find_all("img", {"class": "bh-photo-modal-grid-image"}, limit=10)
await ctx.send(title.text)
for img in imgs:
await ctx.send(img.get("src"))
link_count += 1
這裡可以看到,我在最後面並沒有將照片下載下來,其實discord只要丟圖片連結他就會自動轉換成圖片拉~~
至此我們已經完成全部的功能拉~~