1. 程式人生 > >Python3~爬取某翻譯網頁的單詞與解釋

Python3~爬取某翻譯網頁的單詞與解釋

from urllib import request
from bs4 import BeautifulSoup
import ssl

ssl._create_default_https_context=ssl._create_unverified_context

#一、網路請求頁面
base_url = "https://www.shanbay.com/wordlist/110521/232414/?page=1"
response = request.urlopen(base_url)
html = response.read()

#二、bs4物件建立
soup = BeautifulSoup(html,
'lxml') tr_list=soup.select('.row') for tr in tr_list: td_list=tr.select('td') # print(td_list) if td_list!=[]: word=td_list[0].contents[0].get_text() content=td_list[1].get_text() print(word,content) print('~~~~~~~~~~~~~~~~~~~~~~~')

/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6 /Users/apple/PycharmProjects/stage4/spider/2018_3_9/01homework.py
computational  adj. 計算的,電腦的
~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~
computational  adj. 計算的,電腦的
~~~~~~~~~~~~~~~~~~~~~~~
computational  adj. 計算的,電腦的
~~~~~~~~~~~~~~~~~~~~~~~
mode n. 模式
~~~~~~~~~~~~~~~~~~~~~~~
primitive n. 原始、基元,是後續操作的基礎
~~~~~~~~~~~~~~~~~~~~~~~
gigabyte n. 千兆位元組,是資料單位
~~~~~~~~~~~~~~~~~~~~~~~
storage n. 儲存體,  倉庫
~~~~~~~~~~~~~~~~~~~~~~~
retrieve n. 檢索,恢復
~~~~~~~~~~~~~~~~~~~~~~~
algorithm  n. 演算法
~~~~~~~~~~~~~~~~~~~~~~~
accomplish  vt. 完成
~~~~~~~~~~~~~~~~~~~~~~~
scheme n. 方案, 計劃,
v. 設計, 體系, 結構,
~~~~~~~~~~~~~~~~~~~~~~~
compute  vt. 計算
~~~~~~~~~~~~~~~~~~~~~~~
code n. 碼,密碼
vt. 把...編碼
~~~~~~~~~~~~~~~~~~~~~~~
halt v 停止
~~~~~~~~~~~~~~~~~~~~~~~
computation n. 計算,計算方法,計算結果
~~~~~~~~~~~~~~~~~~~~~~~
knowledge  n. 知識,瞭解
~~~~~~~~~~~~~~~~~~~~~~~
declarative adj. 說明的, 陳述的
declarative knowledge 陳述性知識
~~~~~~~~~~~~~~~~~~~~~~~
imperative adj. 命令式的,互動的
imperative knowledge 互動性知識
~~~~~~~~~~~~~~~~~~~~~~~
recipe n. 掛起,暫停
~~~~~~~~~~~~~~~~~~~~~~~
evaluate  vt. 評估,評價
~~~~~~~~~~~~~~~~~~~~~~~
square root 平方根 the square root of a number x
x的平方根
~~~~~~~~~~~~~~~~~~~~~~~
deduce vt. 演繹,推斷
~~~~~~~~~~~~~~~~~~~~~~~


Process finished with exit code 0