python爬虫(数据获取——selenium)

环境测试

from selenium import webdriver

chromedriver_path = r"C:\Program Files\Google\Chrome\Application\chromedriver.exe"
driver = webdriver.Chrome()

url = "https://www.xinpianchang.com/discover/article?from=navigator"
driver.get(url)

driver.close()

常用API

python爬虫(数据获取——selenium)_第1张图片

操作页面元素 

python爬虫(数据获取——selenium)_第2张图片python爬虫(数据获取——selenium)_第3张图片

from selenium import webdriver
import json

chromedriver_path = r""
driver = webdriver.Chrome()
url = "https://passport.xinpianchang.com/login?redirect_uri=https%3A%2F%2Fwww.xinpianchang.com%2Fuser%2F14226548&mode=quick&type=phone"
driver.get(url)
with open(r"C:\Users\lenovo\Desktop\a.txt", 'r', encoding='utf-8') as rStream:
    read = rStream.read()

replace = read.replace("'", '"').replace("True", "true").replace("False", "false").replace("Null", "null")
with open(r"", 'w', encoding='utf-8') as wStream:
    write = wStream.write(replace)

with open(r"", 'r', encoding='utf-8') as rStream:
    read = rStream.read()

import json

loads = json.loads(read)
print(loads)
for c in loads:
    driver.add_cookie(c)

driver.get("https://www.xinpianchang.com/")

你可能感兴趣的:(python,爬虫,开发语言)