<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          不會(huì)這幾個(gè)庫(kù),都不敢說(shuō)我會(huì)Python爬蟲

          共 2790字,需瀏覽 6分鐘

           ·

          2020-11-08 02:25

          很多朋友不知道Python爬蟲怎么入門,怎么學(xué)習(xí),到底要學(xué)習(xí)哪些內(nèi)容。今天我來(lái)給大家說(shuō)說(shuō)學(xué)習(xí)爬蟲,我們必須掌握的一些第三方庫(kù)。


          廢話不多說(shuō),直接上干貨。




          1

          ?請(qǐng)求庫(kù)



          1. requests


          GitHub:https://github.com/psf/requests


          requests庫(kù)應(yīng)該是現(xiàn)在做爬蟲最火最實(shí)用的庫(kù)了,非常的人性化。有關(guān)于它的使用我之前也寫過(guò)一篇文章?一起看看Python之Requests庫(kù)?,大家可以去看一下。


          有關(guān)于requests最詳細(xì)的使用方法,大家可以參考官方文檔:https://requests.readthedocs.io/en/master/


          使用小案例:

          >>> import requests>>> r = requests.get('https://api.github.com/user', auth=('user', 'pass'))>>> r.status_code200>>> r.headers['content-type']'application/json; charset=utf8'>>> r.encoding'utf-8'>>> r.textu'{"type":"User"...'>>> r.json(){u'disk_usage': 368627, u'private_gists': 484, ...}



          2. urllib3


          GitHub:https://github.com/urllib3/urllib3


          urllib3是一個(gè)非常強(qiáng)大的http請(qǐng)求庫(kù),提供一系列的操作URL的功能。


          有關(guān)于它的詳細(xì)使用方法可以參考:https://urllib3.readthedocs.io/en/latest/


          使用小案例:

          >>> import urllib3>>> http = urllib3.PoolManager()>>> r = http.request('GET', 'http://httpbin.org/robots.txt')>>> r.status200>>> r.data'User-agent: *\nDisallow: /deny\n'



          3.selenium


          GitHub:https://github.com/SeleniumHQ/selenium


          自動(dòng)化測(cè)試工具。一個(gè)調(diào)用瀏覽器的 driver,通過(guò)這個(gè)庫(kù)你可以直接調(diào)用瀏覽器完成某些操作,比如輸入驗(yàn)證碼。


          對(duì)于這個(gè)庫(kù)并非只是Python才能用,像JAVA、Python、C#等都能夠使用selenium這個(gè)庫(kù)


          有關(guān)于Python語(yǔ)言如何去使用這個(gè)庫(kù),大家可以去訪問(wèn)https://seleniumhq.github.io/selenium/docs/api/py/ 查看官方文檔



          使用小案例:

          from selenium import webdriver
          browser = webdriver.Firefox()browser.get('http://seleniumhq.org/')



          4.aiohttp


          GitHub:https://github.com/aio-libs/aiohttp


          基于 asyncio 實(shí)現(xiàn)的 HTTP 框架。異步操作借助于 async/await 關(guān)鍵字,使用異步庫(kù)進(jìn)行數(shù)據(jù)抓取,可以大大提高效率。


          這個(gè)屬于進(jìn)階爬蟲時(shí)候必須掌握的異步庫(kù)。有關(guān)于aiohttp的詳細(xì)操作,可以去官方文檔:https://aiohttp.readthedocs.io/en/stable/


          使用小案例:

          import aiohttpimport asyncio
          async def fetch(session, url): async with session.get(url) as response: return await response.text()
          async def main(): async with aiohttp.ClientSession() as session: html = await fetch(session, 'http://python.org') print(html)
          if __name__ == '__main__': loop = asyncio.get_event_loop() loop.run_until_complete(main())



          2

          ?解析庫(kù)?




          1、beautifulsoup


          官方文檔:https://www.crummy.com/software/BeautifulSoup/


          html 和 XML 的解析,從網(wǎng)頁(yè)中提取信息,同時(shí)擁有強(qiáng)大的API和多樣解析方式。一個(gè)我經(jīng)常使用的解析庫(kù),對(duì)于html的解析是非常的好用。對(duì)于寫爬蟲的人來(lái)說(shuō)這也是必須掌握的庫(kù)。



          2、lxml


          GitHub:https://github.com/lxml/lxml


          支持HTML和XML的解析,支持XPath解析方式,而且解析效率非常高。



          3、pyquery


          GitHub:https://github.com/gawel/pyquery


          jQuery 的 Python 實(shí)現(xiàn),能夠以 jQuery 的語(yǔ)法來(lái)操作解析 HTML 文檔,易用性和解析速度都很好。





          3

          ?數(shù)據(jù)存儲(chǔ)庫(kù)?



          1、pymysql


          GitHub:https://github.com/PyMySQL/PyMySQL


          官方文檔:https://pymysql.readthedocs.io/en/latest/


          一個(gè)純 Python 實(shí)現(xiàn)的 MySQL 客戶端操作庫(kù)。非常的實(shí)用、非常的簡(jiǎn)單。



          2、pymongo


          GitHub:https://github.com/mongodb/mongo-python-driver


          官方文檔:https://api.mongodb.com/python/


          顧名思義,一個(gè)用于直接連接 mongodb 數(shù)據(jù)庫(kù)進(jìn)行查詢操作的庫(kù)。



          3、redisdump


          使用方法:https://blog.csdn.net/zhwitbird/article/details/81279406


          redis-dump是將redis和json互轉(zhuǎn)的工具;redis-dump是基于ruby開發(fā),需要ruby環(huán)境,而且新版本的redis-dump要求2.2.2以上的ruby版本,centos中yum只能安裝2.0版本的ruby。需要先安裝ruby的管理工具rvm安裝高版本的ruby;

          瀏覽 66
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  欧美A∨在线| 久久久久久草 | 黄色在线观看视频 | 内射七八高清视频 | 亚州无码在线 |