Python3 站長工具-百度拓詞抓取關鍵詞

Python3 站長工具-百度拓詞抓取關鍵詞

import urllib.request as request
import lxml.html as html
import time

a = 1
b = 0
xpath = “//a[@class=“ellipsis block”]/span/text()”
f = open(“yangshu.txt”,“w”)
while a <= 2:
url = “http://stool.chinaz.com/baidu/words.aspx?kw=%E6%9D%A8%E6%A0%91&
by=0&page=”+str(a)
print(url)
data = request.urlopen(url).read().decode(“utf-8”)
dom = html.document_fromstring(data)
links = dom.xpath(xpath)
print(links)
for link in links:
info = link
print(info)
print("*"*100)
f.write(info)
f.write("\n")

a  += 1
time.sleep( 5 )

f.close()

發佈了13 篇原創文章 · 獲贊 14 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章