Skip to content

Commit

Permalink
add "Python雜記|在repl.it上使用selenium"
Browse files Browse the repository at this point in the history
  • Loading branch information
kkian481718 committed Aug 16, 2024
1 parent a246a3e commit 6bb064c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function Home({ posts }) {
<div className="divide-y divide-gray-200 dark:divide-gray-700">
<div className="space-y-2 pb-8 pt-6 md:space-y-5">
<h1 className="text-3xl font-extrabold leading-9 tracking-tight text-gray-900 dark:text-gray-100 sm:text-4xl sm:leading-10 md:text-6xl md:leading-14">
Latest
最新文章
</h1>
<p className="text-lg leading-7 text-gray-500 dark:text-gray-400">
{siteMetadata.description}
Expand Down
38 changes: 38 additions & 0 deletions data/blog/coding/python/replit-selenium.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
title: "Python雜記|在repl.it上使用selenium"
date: '2024-07-23'
tags: ['coding', 'python']
authors: ['default']
draft: false
summary: 如果你跟我一樣想用reply.it爬蟲,而且很反骨想用selenium,這篇手把手教學讓你成功執行第一隻自己的爬蟲!
---

## 背景
如果你跟我一樣想用reply.it爬蟲,而且很反骨想用selenium,那麼你來對地方了!

## 1. 編輯replit.nix
- 先按左邊files,找到右上角的三個點點
- 按show hidden files
- 編輯remplit.nix,加入下面兩個套件
```nix:remplit.nix
{pkgs}: {
deps = [
pkgs.chromium
pkgs.chromedriver
];
}
```

## 2. 回到 main.py,初始化chromedriver
```python:main.py
# 引用webdriver套件
from selenium import webdriver

# Chromedriver設定
chrome_options = Options()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome(options=chrome_options)
```

## 3. 大功告成:)

0 comments on commit 6bb064c

Please sign in to comment.