這篇文章主要講解了“怎么用Python爬取音標(biāo)”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“怎么用Python爬取音標(biāo)”吧!
10年積累的網(wǎng)站制作、成都網(wǎng)站建設(shè)經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶對(duì)網(wǎng)站的新想法和需求。提供各種問題對(duì)應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先網(wǎng)站設(shè)計(jì)制作后付款的網(wǎng)站建設(shè)流程,更有徽州免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
# -*- coding: UTF-8 -*- import requests import time from bs4 import BeautifulSoup f = open('./words.txt') fw = open('./result.txt','a') line = f.readline() index = 0 while line: index = index+1 url = "https://www.oxfordlearnersdictionaries.com/definition/english/" + line.strip() print(str(index) + ":" + url) wbdata = requests.get(url,headers={'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.75 Safari/537.36'}).text soup = BeautifulSoup(wbdata,'html.parser') news_titles = soup.select("span.pron-g > span.phon") # print(news_titles) result = '' for n in news_titles: title = n.get_text() if 'NAmE' in title: result += '['+title.replace('NAmE','').replace('//','') + ']' print(result) fw.write((result + "\n").encode("utf-8")) line = f.readline() time.sleep(0.1) fw.close() f.close()
感謝各位的閱讀,以上就是“怎么用Python爬取音標(biāo)”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對(duì)怎么用Python爬取音標(biāo)這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!