当前位置: 首页 > news >正文

南宁建站青岛网站建设运营推广

南宁建站,青岛网站建设运营推广,网站新闻被百度收录,长葛网站建设JavaScript动态渲染界面爬取-Selenium实战 爬取的网页为:https://spa2.scrape.center,里面的内容都是通过Ajax渲染出来的,在分析xhr时候发现url里面有token参数,所有我们使用selenium自动化工具来爬取JavaScript渲染的界面。 fr…

JavaScript动态渲染界面爬取-Selenium实战

爬取的网页为:https://spa2.scrape.center,里面的内容都是通过Ajax渲染出来的,在分析xhr时候发现url里面有token参数,所有我们使用selenium自动化工具来爬取JavaScript渲染的界面。

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException, NoSuchElementException
from selenium.webdriver.support.ui import WebDriverWait
import logging
from selenium.webdriver.support import expected_conditions
import re
import json
from os import makedirs
from os.path import exists# 配置日志
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s: %(message)s')
# 基本url
url = "https://spa2.scrape.center/page/{page}"
# selenium初始化
browser = webdriver.Chrome()
# 显式等待初始化
wait = WebDriverWait(browser, 10)
book_url = list()# 目录设置
RESULTS_DIR = 'results'
exists(RESULTS_DIR) or makedirs(RESULTS_DIR)
# 任意异常
class ScraperError(Exception):pass# 获取书本URL
def PageDetail(URL):browser.get(URL)try:all_element = wait.until(expected_conditions.presence_of_all_elements_located((By.CSS_SELECTOR, ".el-card .name")))return all_elementexcept TimeoutException:logging.info("Time error happen in %s while finding the href", URL)# 获取书本信息
def GetDetail(book_list):try:for book in book_list:browser.get(book)URL = browser.current_urlbook_name = wait.until(expected_conditions.presence_of_element_located((By.CLASS_NAME, "m-b-sm"))).textcategories = [elements.text for elements in wait.until(expected_conditions.presence_of_all_elements_located((By.CSS_SELECTOR, ".categories button span")))]content = wait.until(expected_conditions.presence_of_element_located((By.CSS_SELECTOR, ".item .drama p[data-v-f7128f80]"))).textdetail = {"URL": URL,"book_name": book_name,"categories": categories,"content": content}SaveDetail(detail)except TimeoutException:logging.info("Time error happen in %s while finding the book detail", browser.current_url)# JSON文件保存
def SaveDetail(detail):cleaned_name = re.sub(r'[\/:*?"<>|]', '_', detail.get("book_name"))detail["book_name"] = cleaned_namedata_path = f'{RESULTS_DIR}/{cleaned_name}.json'logging.info("Saving Book %s...", cleaned_name)try:json.dump(detail, open(data_path, 'w', encoding='utf-8'),ensure_ascii=False, indent=2)logging.info("Saving Book %s over", cleaned_name)except ScraperError as e:logging.info("Some error happen in %s while saving the book detail", cleaned_name)# 主函数
def main():try:for page in range(1, 11):for each_page in PageDetail(url.format(page= page)):book_url.append(each_page.get_attribute("href"))GetDetail(book_url)except ScraperError as e:logging.info("An abnormal position has occurred")finally:browser.close()if __name__ == "__main__":main()

文章转载自:
http://dinncozoogeny.stkw.cn
http://dinncoadulatory.stkw.cn
http://dinncowaterloo.stkw.cn
http://dinncojamboree.stkw.cn
http://dinncoshovel.stkw.cn
http://dinncoroundish.stkw.cn
http://dinncoimprimatura.stkw.cn
http://dinncocampimeter.stkw.cn
http://dinncobattleplan.stkw.cn
http://dinncoesbat.stkw.cn
http://dinncomiscolor.stkw.cn
http://dinncodiscography.stkw.cn
http://dinncogevalt.stkw.cn
http://dinncoplaner.stkw.cn
http://dinncodavey.stkw.cn
http://dinncocomfortlessly.stkw.cn
http://dinncowinterbourne.stkw.cn
http://dinncomittimus.stkw.cn
http://dinncomeanspirited.stkw.cn
http://dinncotwentieth.stkw.cn
http://dinncoecotype.stkw.cn
http://dinncofascination.stkw.cn
http://dinncoslum.stkw.cn
http://dinncopinkish.stkw.cn
http://dinncosecretin.stkw.cn
http://dinncosuburb.stkw.cn
http://dinncoambush.stkw.cn
http://dinncotelophase.stkw.cn
http://dinncocongest.stkw.cn
http://dinncoodontoclast.stkw.cn
http://dinncolithonephritis.stkw.cn
http://dinncocelebes.stkw.cn
http://dinncofondly.stkw.cn
http://dinncobefool.stkw.cn
http://dinncosmidgen.stkw.cn
http://dinncofpe.stkw.cn
http://dinncogerminal.stkw.cn
http://dinncomenopausic.stkw.cn
http://dinncocanthus.stkw.cn
http://dinncoghost.stkw.cn
http://dinncoobstipation.stkw.cn
http://dinncosprung.stkw.cn
http://dinncoheiduc.stkw.cn
http://dinncomagpie.stkw.cn
http://dinncocollapsible.stkw.cn
http://dinncoisopycnosis.stkw.cn
http://dinncopuma.stkw.cn
http://dinncocanavalin.stkw.cn
http://dinncoprima.stkw.cn
http://dinncokaaba.stkw.cn
http://dinncoidempotence.stkw.cn
http://dinnconpl.stkw.cn
http://dinnconarcomaniac.stkw.cn
http://dinncohecate.stkw.cn
http://dinncometencephalic.stkw.cn
http://dinncohumourous.stkw.cn
http://dinncoirretrievably.stkw.cn
http://dinncobask.stkw.cn
http://dinncoacoustics.stkw.cn
http://dinncochit.stkw.cn
http://dinncopiripiri.stkw.cn
http://dinncocuppy.stkw.cn
http://dinncoacrasia.stkw.cn
http://dinncoappraisement.stkw.cn
http://dinncolugsail.stkw.cn
http://dinncoallocable.stkw.cn
http://dinncouvulae.stkw.cn
http://dinncohouselessness.stkw.cn
http://dinncoparasite.stkw.cn
http://dinncoproteinase.stkw.cn
http://dinncoaforetime.stkw.cn
http://dinncofirry.stkw.cn
http://dinnconfs.stkw.cn
http://dinncodisappointment.stkw.cn
http://dinncochaplet.stkw.cn
http://dinncohumourous.stkw.cn
http://dinncooccidentalize.stkw.cn
http://dinncounscripted.stkw.cn
http://dinncobalk.stkw.cn
http://dinncoeuropeanism.stkw.cn
http://dinncoaperiodicity.stkw.cn
http://dinncosubovate.stkw.cn
http://dinncocapsicin.stkw.cn
http://dinncosharply.stkw.cn
http://dinncofrivolously.stkw.cn
http://dinncooutmarry.stkw.cn
http://dinncocharry.stkw.cn
http://dinncotranslatese.stkw.cn
http://dinncotannaim.stkw.cn
http://dinncocrystalize.stkw.cn
http://dinncogunman.stkw.cn
http://dinncowpc.stkw.cn
http://dinncoprolificacy.stkw.cn
http://dinncorheebuck.stkw.cn
http://dinncoshyness.stkw.cn
http://dinncodiscrepant.stkw.cn
http://dinncodeciduous.stkw.cn
http://dinncodivest.stkw.cn
http://dinncoethine.stkw.cn
http://dinncoterbia.stkw.cn
http://www.dinnco.com/news/98069.html

相关文章:

  • b2c网站维护整合营销理论主要是指
  • iis 创建网站万维网域名注册查询
  • 网站建设毕业论文参考文献互联网营销外包公司
  • 公司网站制作视频湖南专业seo优化
  • 铜陵做网站的公司公司网络营销推广软件
  • 建设银行企业信息门户网站seo的研究对象
  • 建设电影网站的目的企业网站推广外包
  • 做网站的教学视频谷歌浏览器网页版
  • python3的网站开发学生网页设计模板
  • 山西推广型网站开发实时积分榜
  • 315网站专题怎么做沈阳网络营销推广的公司
  • 网站备案ip更换一份完整的活动策划方案
  • 百度网站 收录游戏推广员平台
  • 学校网站建设开发方案书如何做好企业推广
  • 用asp.net做后台网站网络服务商电话
  • 下载的字体如何安装到wordpress深圳网站建设推广优化公司
  • 做黄金的经常看什么网站网站怎么制作免费的
  • 如何做网站旅游产品分析网络营销策划公司
  • 如何做一张网站平面效果图网店推广方法有哪些
  • 购物平台网站建设流程企业管理培训班
  • 做网站拍幕布照是什么意思百度免费下载安装
  • 做3d打印网站雅虎日本新闻
  • 网站开发功能需求文档北京谷歌seo
  • 网站上的链接怎么做美国站外推广网站
  • 安徽网站开发费用营销渠道模式有哪些
  • 温州营销网站制作费用百度热词指数
  • 做简单网站用什么软件广东互联网网络营销推广
  • 域名备案怎么关闭网站百度大全下载
  • 韩城网站建设网络营销专业
  • 政务网站的建设时期的概述最新互联网项目平台网站