|
|
@ -109,6 +109,7 @@ pip how selenium
|
|
|
|
from selenium import webdriver
|
|
|
|
from selenium import webdriver
|
|
|
|
from selenium.webdriver.chrome.options import Options
|
|
|
|
from selenium.webdriver.chrome.options import Options
|
|
|
|
chrome_options = Options()
|
|
|
|
chrome_options = Options()
|
|
|
|
|
|
|
|
# chrome_options.add_argument('lang=zh_CN.UTF-8') # 设置中文
|
|
|
|
chrome_options.add_argument('--headless') # 无界面
|
|
|
|
chrome_options.add_argument('--headless') # 无界面
|
|
|
|
chrome_options.add_argument('--no-sandbox') # 解决DevToolsActivePort文件不存在报错问题
|
|
|
|
chrome_options.add_argument('--no-sandbox') # 解决DevToolsActivePort文件不存在报错问题
|
|
|
|
chrome_options.add_argument('--disable-gpu') # 禁用GPU硬件加速。如果软件渲染器没有就位,则GPU进程将不会启动。
|
|
|
|
chrome_options.add_argument('--disable-gpu') # 禁用GPU硬件加速。如果软件渲染器没有就位,则GPU进程将不会启动。
|
|
|
@ -149,9 +150,17 @@ html1 = etree.parse('test.html',etree.HTMLParser(encoding='utf-8'))
|
|
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### ChromeDriver
|
|
|
|
请求头,cookie等
|
|
|
|
|
|
|
|
|
|
|
|
下载 [ChromeDriver](https://chromedriver.chromium.org/home) 放到 python 根目录就行
|
|
|
|
```python
|
|
|
|
|
|
|
|
# 访问 https://httpbin.org/get?show_env=1 可以返回当前浏览器的请求信息
|
|
|
|
|
|
|
|
options.add_argument('lang=zh_CN.UTF-8')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ChromeDriver
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
下载 [ChromeDriver](https://chromedriver.chromium.org/home) 放到当前目录就行(如果是放在 python 根目录可以不用在实例化 selenium 时指定chromedriver 路径)
|
|
|
|
|
|
|
|
|
|
|
|
### Redis
|
|
|
|
### Redis
|
|
|
|
|
|
|
|
|
|
|
@ -199,4 +208,4 @@ redisconn = redis.Redis(host = '127.0.0.1', port = '6379', password = 'x', db =
|
|
|
|
|
|
|
|
|
|
|
|
11,[如何理解Python装饰器?- 知乎](https://www.zhihu.com/question/26930016/answer/360300235)
|
|
|
|
11,[如何理解Python装饰器?- 知乎](https://www.zhihu.com/question/26930016/answer/360300235)
|
|
|
|
|
|
|
|
|
|
|
|
12,
|
|
|
|
12,[【自动化】selenium设置请求头](https://www.jianshu.com/p/419eb4e00963)
|