您好,登錄后才能下訂單哦!
這篇文章主要講解了“怎么用Python爬取音標”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“怎么用Python爬取音標”吧!
# -*- 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爬取音標”的內容了,經過本文的學習后,相信大家對怎么用Python爬取音標這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。