鱼C论坛

 找回密码
 立即注册
查看: 2327|回复: 8

[已解决]请问为什么这个会报语法错误?哪里错了?

[复制链接]
发表于 2017-8-18 18:45:10 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
import urllib
import re

def getHtml(url):
    page = urllib.urlopen(url)
    html = page.read()
    return html

def getImg(html):
    reg = r'src="(.+?\.jpg)" pic_ext'
    imgre = re.compile(reg)
    imglist = re.findall(imgre,html)
    x = 0
    for imgurl in imglist:
        urllib.urlretrieve(imgurl,'%s.jpg' % x)
        x+=1
   

html = getHtml("http://tieba.baidu.com/p/2460150866")

print getImg(html)
最佳答案
2017-8-18 18:59:18
jww 发表于 2017-8-18 18:50
我试过的,还是一样错误

能不能好好说话?错误确实有,是一样的错误吗?

也免得你找错误了。给你上代码。答案还得靠自己解决
  1. import urllib.request
  2. import re

  3. def getHtml(url):
  4.     page = urllib.request.urlopen(url)
  5.     html = page.read().decode("utf-8")
  6.     return html

  7. def getImg(html):
  8.     reg = r'src="(.+?\.jpg)" pic_ext'
  9.     imgre = re.compile(reg)
  10.     imglist = imgre.findall(html)
  11.     x = 0
  12.     for imgurl in imglist:
  13.         urllib.request.urlretrieve(imgurl,'%s.jpg' % x)
  14.         x+=1
  15.    

  16. html = getHtml("http://tieba.baidu.com/p/2460150866")

  17. print(getImg(html))
复制代码

搞我一桌面图片
2017-08-18_185711.png
QQ截图20170818184437.jpg
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2017-8-18 18:46:15 | 显示全部楼层
print(getImg(html))
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-8-18 18:50:50 | 显示全部楼层
ba21 发表于 2017-8-18 18:46
print(getImg(html))

我试过的,还是一样错误
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-8-18 18:54:12 | 显示全部楼层
jww 发表于 2017-8-18 18:50
我试过的,还是一样错误

因为你复制别人的代码放在idle里面 ,这个是要放在新建的Py文件中的
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-8-18 18:59:18 | 显示全部楼层    本楼为最佳答案   
jww 发表于 2017-8-18 18:50
我试过的,还是一样错误

能不能好好说话?错误确实有,是一样的错误吗?

也免得你找错误了。给你上代码。答案还得靠自己解决
  1. import urllib.request
  2. import re

  3. def getHtml(url):
  4.     page = urllib.request.urlopen(url)
  5.     html = page.read().decode("utf-8")
  6.     return html

  7. def getImg(html):
  8.     reg = r'src="(.+?\.jpg)" pic_ext'
  9.     imgre = re.compile(reg)
  10.     imglist = imgre.findall(html)
  11.     x = 0
  12.     for imgurl in imglist:
  13.         urllib.request.urlretrieve(imgurl,'%s.jpg' % x)
  14.         x+=1
  15.    

  16. html = getHtml("http://tieba.baidu.com/p/2460150866")

  17. print(getImg(html))
复制代码

搞我一桌面图片
2017-08-18_185711.png
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-8-18 19:01:01 | 显示全部楼层
还有请用.py文件运行代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-8-18 19:09:42 | 显示全部楼层
对不起,我没有恶意的,刚刚学这个,可能自己比较笨吧,给您添麻烦了。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-8-18 19:44:37 | 显示全部楼层
谢谢您,我搞定了,祝您生活愉快!
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2017-8-18 19:46:43 | 显示全部楼层
jww 发表于 2017-8-18 19:09
对不起,我没有恶意的,刚刚学这个,可能自己比较笨吧,给您添麻烦了。

慢慢来,不急
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-3-1 16:10

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表