日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python实现一个字典

發布時間:2025/3/21 python 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python实现一个字典 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#!/usr/bin/python #-*-coding:utf-8-*-from selenium import webdriver from bs4 import BeautifulSoup #上面兩個都是第三方庫,請自行下載,還有PhantomJS也要去官網下載安裝 def main():while True:word = raw_input("輸入要查詢的單詞:")driver = webdriver.PhantomJS(r'C:\phantomjs-2.1.1-windows\bin\phantomjs.exe')url = "https://www.baidu.com/s?wd=%s"%worddriver.get(url)#下載網頁并且渲染Javascriptsoup = BeautifulSoup(driver.page_source,"html.parser")#用Beautiful解析網頁detail = soup.select("table.op_dict3_english_result_table tbody tr td span")sentence = soup.select("div.op_dict3_lineone_result.c-clearfix span")chinese = soup.find('div',attrs={"class":"op_dict3_linetwo_result"})if len(detail)==0 or sentence==0:print "解析錯誤,請確定輸入的是英語單詞"continuewordDict = {}for i in range(0,len(detail),2):try:wordDict[detail[i].get_text().strip()]=detail[i+1].get_text().strip().replace("\n","")except:breakfor key in wordDict.keys():if '[' in key:print wordDict[key].replace(" "*6,"")continueprint key+" "+wordDict[key]for i in sentence:print i.get_text()if chinese!=None:print chinese.get_text() if __name__== "__main__":main()

總結

以上是生活随笔為你收集整理的python实现一个字典的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。