当我们要进行长尾关键词挖掘的时候,查询搜索引擎的相关搜索是一个非常有用的方法,下面就教你怎么挖掘yahoo搜索的长尾关键词。
一、成果展示
二、代码
import requests from xml.etree import ElementTree class keywords(): def __init__(self): self.user_agent="Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.149 Safari/537.36" self.Connection="close" def get_search_suggest(self,key): try: html=requests.get("http://search.yahoo.com/sugg/gossip/gossip-us-ura/?command=%s"%key).text words=self.__read_xml(html) print(words) return words except: print("Some thing error!") def __read_xml(self,text): words="" root=ElementTree.fromstring(text) node_findall = root.findall("s") for i in node_findall: words=words+i.attrib["k"]+"\n" return words yahoo=keywords() yahoo.get_search_suggest("china")