如果在centos上使用,需要安装下面的依赖

yum install pango.x86_64 libXcomposite.x86_64 libXcursor.x86_64 libXdamage.x86_64 libXext.x86_64 libXi.x86_64 libXtst.x86_64 cups-libs.x86_64 libXScrnSaver.x86_64 libXrandr.x86_64 GConf2.x86_64 alsa-lib.x86_64 atk.x86_64 gtk3.x86_64 -y

执行代码

import asyncio
import pyppeteer
from collections import namedtuple Response = namedtuple("rs", "title url html cookies headers history status") async def get_html(url, timeout=30):
# 默认30s
browser = await pyppeteer.launch(headless=True, args=['--no-sandbox'])
page = await browser.newPage()
res = await page.goto(url, options={'timeout': int(timeout * 1000)})
data = await page.content()
title = await page.title()
resp_cookies = await page.cookies()
resp_headers = res.headers
resp_history = None
resp_status = res.status
response = Response(title=title, url=url,
html=data,
cookies=resp_cookies,
headers=resp_headers,
history=resp_history,
status=resp_status)
return response if __name__ == '__main__':
url_list = ["http://www.10086.cn/index/tj/index_220_220.html", "http://www.10010.com/net5/011/",
"http://python.jobbole.com/87541/"]
task = (get_html(url) for url in url_list) loop = asyncio.get_event_loop()
results = loop.run_until_complete(asyncio.gather(*task))
for res in results:
print(res.title)

pyppeteer爬虫例子的更多相关文章

  1. nodejs写的一个网页爬虫例子(坏链率)

    因为工作需要,用nodejs写了个简单的爬虫例子,之前也没用过nodejs,连搭环境加写大概用了5天左右,so...要多简陋有多简陋,放这里给以后的自己看~~ 整体需求是:给一个有效的URL地址,返回 ...

  2. Python网络爬虫 - 一个简单的爬虫例子

    下面我们创建一个真正的爬虫例子 爬取我的博客园个人主页首页的推荐文章列表和地址 scrape_home_articles.py from urllib.request import urlopen f ...

  3. python-入门的第一个爬虫例子

    前言: 此文为大家入门爬虫来做一次简单的例子,让大家更直观的来了解爬虫. 本次我们利用 Requests 和正则表达式来抓取豆瓣电影的相关内容. 一.本次目标: 我们要提取出豆瓣电影-正在上映电影名称 ...

  4. Python爬虫例子(笔记,不适合参考,愿意看的可以看看)

    话不多说,直接上代码: import re import csv #爬虫的一个小例子,爬的是百度贴吧(网页版)某个帖子的各个楼层的用户名,发言内容和发言时间(使用到了正则表达式) source3.tx ...

  5. 爬虫例子及知识点(scrapy知识点)

    新知识: 新建一个scrapy项目:scrapy startproject xxx(项目名称) 运行一个scrapy项目:scrapy crawl xxx(项目名称) 项目文件说明: 文件说明: • ...

  6. python爬虫学习(二):定向爬虫例子-->使用BeautifulSoup爬取"软科中国最好大学排名-生源质量排名2018",并把结果写进txt文件

    在正式爬取之前,先做一个试验,看一下爬取的数据对象的类型是如何转换为列表的: 写一个html文档: x.html<html><head><title>This is ...

  7. C#爬虫例子

    公司需要抓取新闻,每次手动复制粘贴新闻,太麻烦了,业务人员就提出了要求,需要程序实现自动抓取新闻,因此就写了这个简单的爬虫程序. Html Agility Pack库 这是一个.NET下的HTML解析 ...

  8. 简单的爬虫例子——爬取豆瓣Top250的电影的排名、名字、评分、评论数

    爬取思路: url从网页上把代码搞下来bytes decode ---> utf-8 网页内容就是我的待匹配的字符串ret = re.findall(正则,待匹配的字符串), ret 是所有匹配 ...

  9. Java网络爬虫 - 一个简单的爬虫例子

    WikiScraper.java package master.haku.scrape; import org.jsoup.Jsoup; import org.jsoup.nodes.Document ...

随机推荐

  1. 用DotNetOpenAuth实现基于OAuth 2.0的web api授权 (一)Getting Start

    1. 下载 源码下载 2. build solution,创建虚拟目录: 右健MyContatacts/MyPromo项目,选择Properties,点击左边的Web,点击 Create Virtua ...

  2. linux ssh keys

    1. 原理: SSH 密钥对总是成双出现的,一把公钥,一把私钥.公钥可以自由的放在您所需要连接的 SSH 服务器上,而私钥必须稳妥的保管好. 所谓"公钥登录",原理很简单,就是用户 ...

  3. JDK源码分析(5)Vector

    JDK版本 Vector简介 /** * The {@code Vector} class implements a growable array of * objects. Like an arra ...

  4. Git Pull Github and Gitee or Gitlab

    GitHub实战系列汇总:http://www.cnblogs.com/dunitian/p/5038719.html 缩略Code:https://www.cnblogs.com/dotnetcra ...

  5. AutoCompleteTextView和自定义的CursorAdapter

    用雅虎天气接口和AutoCompleteTextView开发天气应用(1) 2014/03/20 | 分类: ANDROID, 开发 | 2 条评论 | 标签: 天气, 安卓开发 分享到:5 jQue ...

  6. SDL2.0 VLC ubuntu安装和黑屏问题

    开发环境安装: 1,执行:"sudo apt-get build-dep libsdl1.2",确定依赖库都装全了. sdl2.0没有正式发布到ubuntu,使用下面方法安装: h ...

  7. A1102. Invert a Binary Tree

    The following is from Max Howell @twitter: Google: 90% of our engineers use the software you wrote ( ...

  8. STM32 CAN

    STM32普通型芯片的 CAN 有14组过滤器组(互联型有28组过滤器组) ,用以对接收到的帧进行过滤.每组过滤器包括了2个可配置的32位寄存器:CAN_FxR0和 CAN_FxR1.对于过滤器组, ...

  9. Prometheus MySQL_exporter

    MySQL Exporter mysqld_exporter是用来搜集mysql的性能指标的,适用于mysql5.5及其以上版本 程序安装 下载地址:https://prometheus.io/dow ...

  10. loadrunner之WebServices协议脚本编写(三种请求模式)

    以天气预报网站为例:http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl 一.web_service_call模式 步骤如下 ...