python网络爬虫采集联想词示例

yipeiwu_com4年前Python爬虫

python爬虫_采集联想词代码

复制代码 代码如下:

#coding:utf-8
import urllib2
import urllib
import re
import time
from random import choice
#特别提示,下面这个list中的代理ip可能失效,请换上有效的代理ip
iplist  = ['27.24.158.153:81','46.209.70.74:8080','60.29.255.88:8888']

list1 = ["集团","科技"]
for item in list1:
    ip= choice(iplist)
    gjc = urllib.quote(item)
    url = "http://sug.so.360.cn/suggest/word?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":"sMozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.56 Safari/537.17",
                }

    proxy_support = urllib2.ProxyHandler({'http':'http://'+ip})

    opener = urllib2.build_opener(proxy_support)
    urllib2.install_opener( opener )
    req = urllib2.Request(url)

    for key in headers:
        req.add_header(key,headers[key])

    html = urllib2.urlopen(req).read()

    ss = re.findall("\"(.*?)\"",html)
    for item in ss:
        print item
    time.sleep(2)

相关文章

python爬虫 基于requests模块发起ajax的get请求实现解析

python爬虫 基于requests模块发起ajax的get请求实现解析

基于requests模块发起ajax的get请求 需求:爬取豆瓣电影分类排行榜 https://movie.douban.com/中的电影详情数据 用抓包工具捉取 使用ajax加载页面...

Python爬虫实例扒取2345天气预报

Python爬虫实例扒取2345天气预报

寒假里学习了一下Python爬虫,使用最简单的方法扒取需要的天气数据,对,没听错,最简单的方法。甚至没有一个函数封装。。 网址:http://tianqi.2345.com/wea_hi...

利用python爬取斗鱼app中照片方法实例

利用python爬取斗鱼app中照片方法实例

前言 没想到python是如此强大,令人着迷,以前看见图片总是一张一张复制粘贴,现在好了,学会python就可以用程序将一张张图片,保存下来。 最近看到斗鱼里的照片都不错,决定用最新学习...

简单的抓取淘宝图片的Python爬虫

写了一个抓taobao图片的爬虫,全是用if,for,while写的,比较简陋,入门作品。 从网页http://mm.taobao.com/json/request_top_list.h...

python正则表达式爬取猫眼电影top100

用正则表达式爬取猫眼电影top100,具体内容如下 #!/usr/bin/python # -*- coding: utf-8 -*- import json # 快速导...