如何使用 bs4/python 从维基百科站点获取 txt 文件中的单词的搜索结果?
How can i get the search results of a word in txt file from a Wikipedia site using bs4/python?
我在维基百科页面上搜索了一个词 'Eudicots'。 The search url shows 262 titles。我怎样才能把标题写在一个txt文件中。 BeautifulSoup4/python可以吗?怎么样?
import requests, bs4
url = 'https://ta.wikipedia.org/w/index.php?title=specal:Search&limit=500&offset=0&profile=default&search=Eudicots&searchToken=doo0wuq364b1m60hlcb894gt6'
r = requests.get(url)
soup = bs4.BeautifulSoup(r.text, 'lxml')
t_tags = soup.find_all('div', class_="mw-search-result-heading")
with open('a.txt', 'w') as f:
for t in t_tags:
print(t.text, file=f)
输出:
இருவித்திலைத் தாவரம்
கழுதைப்பிட்டி-மூலிகை
ஃபபேசியே பூக்குடும்பத்தின் பேரினங்கள் பட்டியல்
வில்வம்
பாலை (மரம்)
சந்தனம்
ஆத்தி
தோடம்பழம்
வேம்பு
நெல்லி
செங்கொடுவேரி
கரந்தை
我在维基百科页面上搜索了一个词 'Eudicots'。 The search url shows 262 titles。我怎样才能把标题写在一个txt文件中。 BeautifulSoup4/python可以吗?怎么样?
import requests, bs4
url = 'https://ta.wikipedia.org/w/index.php?title=specal:Search&limit=500&offset=0&profile=default&search=Eudicots&searchToken=doo0wuq364b1m60hlcb894gt6'
r = requests.get(url)
soup = bs4.BeautifulSoup(r.text, 'lxml')
t_tags = soup.find_all('div', class_="mw-search-result-heading")
with open('a.txt', 'w') as f:
for t in t_tags:
print(t.text, file=f)
输出:
இருவித்திலைத் தாவரம்
கழுதைப்பிட்டி-மூலிகை
ஃபபேசியே பூக்குடும்பத்தின் பேரினங்கள் பட்டியல்
வில்வம்
பாலை (மரம்)
சந்தனம்
ஆத்தி
தோடம்பழம்
வேம்பு
நெல்லி
செங்கொடுவேரி
கரந்தை