NIUBOYI»Home › › 脚本分享 › 中文 | English
微信扫一扫 分享朋友圈

已有 901 人浏览分享

脚本分享    Python: Open a webpage in the current browser to perform automation and crawler tasks

2024-7-9 00:21:27901 0
Often when we scrape data or execute tasks on some platforms, we usually need to log in. When we build scripts, we encounter many errors that need to be fixed, which leads to a problem: every time we launch the browser, it opens a new browser window that is not logged in and has no traces. This is very troublesome because we have to log in again and again. With today's method, we can thoroughly learn how to solve this problem.

Commonly used libraries


```
import pandas as pd
import time
from DrissionPage import ChromiumPage, ChromiumOptions
from loguru import logger
import configparser
```


Steps

1. Write the Google Chrome path into the configuration file.


```
[配置]
浏览器路径=C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe
```


2. Create a Google Chrome shortcut in your project folder, then right-click it and open Properties. In the Target field, enter the following to enable the corresponding port and startup parameters:


```
"C:\Program Files\Google\Chrome\Application\chrome.exe" --remote-debugging-port=9222 --user-data-dir="D:/360MoveData/Users/Administrator/Desktop/DouyinCommenter/ChromeUserProfile"  #替换这里的路径存放数据
```


3. Give this shortcut a new name.

4. Call it normally.

With the above parameter setup method, you can run the project in a fixed browser instead of opening a browser in the monitoring environment.
  • WeChat Official Account

  • Scan to Visit Mobile Site

QQ|NIUBOYI ( 京ICP备17025393号 )|网站地图

GMT+8, 2026-10-30 19:45 , Processed in 0.342714 second(s), 37 queries .

POWERED BY NIUBOYIAI! 主理人:NIUBOYIAI  点亮哥

Copyright © 2001-2020, NIUBOYI AI.