云主机下搭建网页爬虫

1. 相关组件

OS:腾讯云Ubuntu

浏览器:chrome + chromedriver

python爬虫框架: selenium

2.安装部署

2.1 安装chrome

sudo apt-get install libxss1 libappindicator1 libindicator7

wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb

sudo apt install ./google-chrome*.deb

google-chrome-stable --version

google-chrome  --headless --disable-gpu  https://www.baidu.com/

2.2 安装chromedriver

wget https://storage.googleapis.com/chrome-for-testing-public/123.0.6312.58/linux64/chromedriver-linux64.zip

unzip chromedriver-linux64.zip

cp chromedriver /usr/local/bin/

2.3 安装python3

2.4 安装selenium

pip install selenium

2.5 编写爬虫程序

from pyvirtualdisplay import Display
from selenium import webdriver

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')#无头模式,服务器没有图形界面这个必须
chrome_options.add_argument('--disable-gpu')#不需要gpu加速
chrome_options.add_argument('--no-sandbox') # 这个配置很重要
#s = Service('/usr/local/bin/chromedriver')
client = webdriver.Chrome(options=chrome_options)    # 如果没有把chromedriver加入到PATH中,就需要指明路径

#client.get("https://ec.chng.com.cn/channel/home/?SlJfApAfmEBp=1704119704734#/")
#client.get("https://ec.chng.com.cn/channel/home/?SlJfApAfmEBp=1704119704734#/detail?id=12542364")
client.get("https://www.zhihu.com/question/553813879/answer/3440060321")
print (client.page_source.encode('utf-8'))
 
client.quit()

相关推荐

  1. 主机网页爬虫

    2024-03-25 12:30:04       34 阅读
  2. 网站网站主机提供商

    2024-03-25 12:30:04       26 阅读
  3. linux主机NFS服务器

    2024-03-25 12:30:04       55 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-25 12:30:04       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-25 12:30:04       106 阅读
  3. 在Django里面运行非项目文件

    2024-03-25 12:30:04       87 阅读
  4. Python语言-面向对象

    2024-03-25 12:30:04       96 阅读

热门阅读

  1. 3.21 ARM day5

    2024-03-25 12:30:04       37 阅读
  2. C++中类和对象其他内容

    2024-03-25 12:30:04       31 阅读
  3. springboot 整合 Caffine(springboot3.2)

    2024-03-25 12:30:04       42 阅读
  4. 完全背包,LeetCode322. 零钱兑换

    2024-03-25 12:30:04       34 阅读
  5. QT 常用模块介绍以及使用说明

    2024-03-25 12:30:04       40 阅读
  6. 小程序配置服务器域名

    2024-03-25 12:30:04       42 阅读
  7. vscode配置rp2040出错记录

    2024-03-25 12:30:04       37 阅读
  8. 交叉编译

    2024-03-25 12:30:04       39 阅读