python爬蟲——爬取糗事百科笑話

貼一個很基礎的爬取糗事百科笑話的爬蟲,用到了selenium庫。(來源:程序媛)

#-*- coding: utf-8 -*-
from selenium import webdriver
import time

driver = webdriver.Firefox()  #打開瀏覽器 獲取網址
driver.get('https://www.qiushibaike.com/')
time.sleep(3)

elem = driver.find_element_by_id('content-left')
contents = elem.find_elements_by_class_name('content')

i=1
for content in contents:
    print(str(i) + '.' + content.text + '\n')  //這裏content.text是class name content 的文字?
    i+=1

driver.close()
driver.quit()


最近做了幾個小小的爬蟲項目 感覺還是很好玩的 繼續努力


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章