First python demo
2016.02.04
sherryriver
流水账技术
 pv:
爬了一下周杰伦贴吧里一个精品图片贴,学习中,代码比较初级啦
代码奉上:
- 2016-04-05 更新帖
之前用的是urllib库,现在发现了一个更好更高级的工具库 requests库。所以优化了下我的代码demo
__author__ = 'lingo'
import requests import re from bs4 import BeautifulSoup page=1
while page<6:
payload = {'see_lz': '1', 'pn': page} r = requests.get("http://tieba.baidu.com/p/3542842663", params=payload)
soup = BeautifulSoup(r.text) code_div = soup.find_all(class_="d_post_content j_d_post_content clearfix") for code in code_div:
code_img = code.find_all("img",src=re.compile("jpg")) for image in code_img: print "第"+str(page)+"页图片链接:",image["src"]
page = page + 1 else: print("完成")
|
对了,是python2.7的