|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import urllib.request
import re
def open_url(url):
req = urllib.request.Request(url)
req.add_header('user-agent','Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36')
page = urllib.request.urlopen(req)
html = page.read().decode('utf-8')
return html
def get_img(html):
p = r'<img class="BDE_Image" pic_type="0" width="553" height="415" src="[^"]+\.jpg"'
imglist = re.findall(p,html)
for each in imglist:
print(each)
if __name__ == '_main_':
url = "http://tieba.baidu.com/p/5222378167"
get_img(open_url(url))
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>>
============== RESTART: D:\Pycharm project\hello world\tieba.py ==============
>>>
请问代码没错误,可是为啥什么都没运行出来
|
|