關於非同步爬蟲排序的困惑
import asyncio
from asyncio import tasks
import aiohttp #pip install aiohttp
from lxml import etree
for x in range(498232,498242):
async def fetch(session,url):
async with session.get(url) as response:
html=await response.text()
return html
async def parser_content(html):
selector = etree.HTML(html)
title=str(selector.xpath("//div[@class='read_title']//h1[1]/text()")[0])
print(x,title)
async def download_content(url):
async with aiohttp.ClientSession() as session:
html=await fetch(session,url)
await parser_content(html)
tasks=[
asyncio.ensure_future(download_content('https://www.xinshuhaige.com/34953/{}.html'.format(x)))
]
loop=asyncio.get_event_loop()
loop.run_until_complete(asyncio.gather(*tasks))
相關文章
- 基於asyncio、aiohttp、xpath的非同步爬蟲AIHTTP非同步爬蟲
- 關於JavaScript的困惑JavaScript
- 關於爬蟲工具 colly 的問題爬蟲
- 網路爬蟲之關於爬蟲 http 代理的常見使用方式爬蟲HTTP
- 關於物件導向的困惑!物件
- 大規模非同步新聞爬蟲: 用asyncio實現非同步爬蟲非同步爬蟲
- 關於Python爬蟲面試50道題Python爬蟲面試
- 爬蟲(9) - Scrapy框架(1) | Scrapy 非同步網路爬蟲框架爬蟲框架非同步
- 爬蟲學習之基於Scrapy的網路爬蟲爬蟲
- 大規模非同步新聞爬蟲:實現一個同步定向新聞爬蟲非同步爬蟲
- Python微型非同步爬蟲框架Python非同步爬蟲框架
- Python非同步爬蟲(aiohttp版)Python非同步爬蟲AIHTTP
- 爬蟲之多工非同步協程爬蟲非同步
- python多執行緒非同步爬蟲-Python非同步爬蟲試驗[Celery,gevent,requests]Python執行緒非同步爬蟲
- 大規模非同步新聞爬蟲:簡單的百度新聞爬蟲非同步爬蟲
- 【Python學習】爬蟲爬蟲爬蟲爬蟲~Python爬蟲
- 關於一些爬蟲專案教程的整理(轉載)爬蟲
- 基於java的分散式爬蟲Java分散式爬蟲
- 用PyCharm Profile分析非同步爬蟲效率PyCharm非同步爬蟲
- Python 非同步網路爬蟲(2)Python非同步爬蟲
- Python 非同步網路爬蟲 IPython非同步爬蟲
- Python 非同步網路爬蟲(1)Python非同步爬蟲
- 關於四色模型的一點困惑模型
- 關於jive中ForumFactory.getInstance()的困惑
- 網路爬蟲專案開發日誌(一):關於爬蟲專案所涉及的領域知識爬蟲
- 對於反爬蟲偽裝瀏覽器進行爬蟲爬蟲瀏覽器
- 關於反爬蟲,看這一篇就夠了爬蟲
- python和爬蟲代理的關聯Python爬蟲
- 基於 Electron 的爬蟲框架 Nightmare爬蟲框架
- 爬蟲入門(字串相關)爬蟲字串
- 惡意爬蟲?能讓惡意爬蟲遁於無形的小Tips爬蟲
- 爬蟲:多程式爬蟲爬蟲
- 關於爬蟲平臺的架構實現和框架的選型(一)爬蟲架構框架
- 大規模非同步新聞爬蟲的實現思路非同步爬蟲
- 通用爬蟲與聚焦爬蟲爬蟲
- 爬蟲--Scrapy簡易爬蟲爬蟲
- python爬蟲---網頁爬蟲,圖片爬蟲,文章爬蟲,Python爬蟲爬取新聞網站新聞Python爬蟲網頁網站
- 對於同步、非同步、阻塞、非阻塞的幾點淺薄理解非同步