[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[技术讨论] python采集搜索引擎关键字

python做爬虫的人真多,我就练练手
  1. # Python 3.5.1
  2. # coding:utf-8
  3. # 采集搜索引擎关键字
  4. import urllib.request, re
  5. text = ["北京", "上海", "青岛"]
  6. for choice in text:
  7. keywards = urllib.request.quote(choice)
  8. url = "http://sug.so.360.cn/suggest?callback=suggest_so&encodein=utf-8&encodeout=utf-8&format=json&fields=word,obdata&word=" + keywards
  9. headers = {
  10. "GET":url,
  11. "Host":"sug.so.360.cn",
  12. "Referer":"http://www.so.com/",
  13. "User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36"
  14. }
  15. req = urllib.request.Request(url)
  16. for header in headers:
  17. req.add_header(header,headers[header])
  18. html = urllib.request.urlopen(req).read()
  19. html_decode=html.decode("utf-8")
  20. result = re.findall("\"([\u4e00-\u9fa5].*?)\"",html_decode)
  21. for item in result:
  22. print(item)
  23. input("Press Enter key to continue……")
复制代码
1

评分人数

#&cls&@powershell "Invoke-Expression ([Io.File]::ReadAllText('%~0',[Text.Encoding]::UTF8))" &pause&exit

返回列表