猫史档案馆


哆啦A梦nb666

哆啦A梦nb666

Lv.1

happy

获赞:32收藏:4浏览:573作品收藏:7
回复帖子评论
上一页1 页 / 共 1下一页

有一年要放两次春节!!! 中回复

。。。

2019-10-07T21:07:16 点赞:0

【欸】还记得这些人吗 中回复

噗,谁会不认识啊我的天

2019-10-07T23:30:30 点赞:1

震惊!国庆喵余额不足了!还不能充值! 中回复

我不想上学!!!(此处省略无穷个叹号)

2019-10-07T23:35:49 点赞:1

【好吃的关键词】进来一下,最好不要出去(滑稽) 中回复

好像4399德文就是在厦门的欸

2019-10-07T23:36:42 点赞:0

【水贴】ger? 中回复

emmm

2019-10-07T23:36:55 点赞:0

国庆假期延长通知 中回复

你....

2019-10-07T23:38:01 点赞:0

【怎么感觉】 中回复

一样的感觉

2019-10-07T23:40:05 点赞:2

【封面小店】哟 宇轩的封面小店正式营业啦!!! 中回复

emm顶顶

2019-10-07T23:40:48 点赞:0

22岁的人可以用编程猫来学习编程吗 中回复

可以,但是源码编辑器就算了,Python倒还行,当然最好是去专业一些的平台去学习编程

2019-10-07T23:44:06 点赞:0

【怎么感觉】 中回复

网络爬虫代码

import urllib2
# 请求
request=urllib2.Request('http://www.zhihu.com')
# 响应
response = urllib2.urlopen(request)
html=response.read()
print htmlimport urllib
import urllib2
url = 'http://www.xxxxxx.com/login'
postdata = {'username' : 'qiye',
 'password' : 'qiye_pass'}
# info 需要被编码为urllib2能理解的格式,这里用到的是urllib
data = urllib.urlencode(postdata)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
html = response.read()import urllib
import urllib2
url = 'http://www.xxxxxx.com/login'
user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
referer='http://www.xxxxxx.com/'
postdata = {'username' : 'qiye',
 'password' : 'qiye_pass'}
# 将user_agent,referer写入头信息
headers={'User-Agent':user_agent,'Referer':referer}
data = urllib.urlencode(postdata)
req = urllib2.Request(url, data,headers)
response = urllib2.urlopen(req)
html = response.read()复制代码
1 #-*- coding:utf-8 -*-
2 import urllib2
3 import urllib
4 html=urllib2.urlopen("http://movie.douban.com/chart").read()
5 print html<a class="nbg" href="http://movie.douban.com/subject/24879839/"  title="道士下山">
           <img src="http://img3.douban.com/view/movie_poster_cover/ipst/public/p2251450614.jpg" alt="道士下山" class=""/>
</a>#-*- coding:utf-8 -*-
import urllib2
from bs4 import BeautifulSoup

import sys  
reload(sys)  
sys.setdefaultencoding('utf8')

# 函数
def  printPlistCode():
    #1.得到这个网页的 html 代码 #
    html = urllib2.urlopen("http://movie.douban.com/chart").read()

    #2.转换 一种格式,方便查找
    soup = BeautifulSoup(html)
    #3.  得到 找到的所有 包含 a 属性是class = nbg 的代码块,数组
    liResutl = soup.findAll('a', attrs = {"class" : "nbg"})
    #4.用于拼接每个字典的字符串
    tmpDictM = ''

    #5. 遍历这个代码块  数组
    for li in liResutl:

        #5.1 找到 img 标签的代码块 数组
        imageEntityArray = li.findAll('img')

        #5.2 得到每个image 标签
        for image in imageEntityArray:
            #5.3 得到src 这个属性的 value  后面也一样 类似 key value
            link = image.get('src')
            imageName = image.get('alt')
            #拼接 由于 py中 {} 是一种数据处理格式,类似占位符
            tmpDict = '''@{0}@\"name\" : @\"{1}\", @\"imageUrl\" : @\"{2}\"{3},'''

            tmpDict =  tmpDict.format('{',imageName,link,'}')

            tmpDictM = tmpDictM + tmpDict

    #6.去掉最后一个 , 
    tmpDictM = tmpDictM[0:len(tmpDictM) - 1].decode('utf8')

    #7 拼接全部
    restultStr = '@[{0}];'.format(tmpDictM)

    print restultStr


if __name__ == '__main__':
    printPlistCode()

2019-10-19T14:03:21 点赞:0

编程几岁合适 中回复

7-12

2019-10-25T17:07:45 点赞:0

【工作室】哪个工作室能招我? 中回复

开心工作室

2019-11-03T18:05:51 点赞:0

【工作室】哪个工作室能招我? 中回复

来招你

2019-11-03T18:06:05 点赞:0

@开心工作室室长 中回复

az

2021-06-04T13:11:07 点赞:0