抓取数据时,经常遇到有的数据是通过ajax异步调取的,如何通过selenium获取网址所加载的全部请求url地址了,即我们打开开发者工具里面network中记录的请求url列表,可以参考下面代码# -*- coding=utf-8 -*-
import json
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
url="http://www.phper163.com/";
chrome_options = Options()
#chrome_options.add_argument('--no-sandbox')
#chrome_options.add_argument('--disable-dev-shm-usage')
#chrome_options.add
之前很早就用过selenium来模拟抓取些网页,之前在windows电脑上配置的,一直以为selenium需要在图形界面才能使用。最近有个项目需要用到selenium,服务器用的centos,所以研究了下。发现linux命令行模式下也可以安装及使用selenium,并不需要图形相关软件安装。1、安装python3及包管理工具pip32、安装seleniumpip3 install selenium3、下载安装 chrome浏览器yum install https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm安装后,通过执行命令 google-chrome --version 来查看当前chrome浏览器的版本4、安装ChromeDriverhttp://npm.taobao.org/mirrors/chromedriver,注意版本需与浏览器版本对应,然后下对应平台的版本即可。下载后与chrome安装目录放在一起,然后配置至环境变量即可,配置好后shell输入:chromed