This code is to learn the basic syntax of Python, refer to an online video write code, the function is to intercept search engine 360 keywords.
Code:
1 #!/usr/bin/python2 #Encoding:utf-83 4 ImportUrllib5 ImportUrllib26 ImportRe7 Import Time8 fromRandomImportChoice9 TenIPList = ['1.9.189.65:3128','27.24.158.130:80','27.24.158.154:80'] One AListkeywords = ["Group","Technology"] - forIteminchlistkeywords: -IP =Choice (iplist) theGJC =urllib.quote (item) -URL ="http://sug.so.360.cn/suggest?callback=suggest_so&encodein=utf-8&encodeout=utf-8&word="+GJC -headers = { - "GET": URL, + "Host":"sug.so.360.cn", - "Referer":"http://www.so.com/", + "user-agent":"mozilla/5.0 (X11; Linux i686) applewebkit/537.36 (khtml, like Gecko) Ubuntu chromium/37.0.2062.120 chrome/37.0.2062.120 safari/537.36 " A } at - #Proxy_support = urllib2. Proxyhandler ({"http": "//" +ip}) - - #opener = Urllib2.build_opener (proxy_support) - #Urllib2.install_opener (opener) -req =Urllib2. Request (URL) in - forKeyinchheaders: to Req.add_header (Key, Headers[key]) + -HTML =Urllib2.urlopen (req). Read () the PrintHTML * $SS = Re.findall ("\"(.*?) \"", HTML)Panax Notoginseng forIteminchSS: - PrintItem the +Time.sleep (3)
The main use of Python from the I-band of several libraries, usage can view the help document.
Python intercepts search engine keywords