参考小甲鱼《零基础入门学习python》第61讲的代码进行爬虫遇到了问题
我参考了小甲鱼的代码进行爬虫但是程序既没有报错也没有运行结果
请问这是为什么呢
希望有大佬指点!!
谢谢大家!!!
代码:
import re
import urllib.request
import time
import socket
def open_url(url):
socket.setdefaulttimeout(20)
time.sleep(10)
proxy_support = urllib.request.ProxyHandler({'http':'61.135.217.7'})
opener = urllib.request.build_opener(proxy_support)
urllib.request.install_opener(opener)
req = urllib.request.Request(url)
req.add_header('User-Agent','Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.221 Safari/537.36 SE 2.X MetaSr 1.0')
page = urllib.request.urlopen(req)
html = page.read().decode('utf-8')
return html
def get(html):
p = r'(?:(?:?\d?\d|2\d|255)\.){3}(?:?\d?\d|2\d|25)'
iplist = re.findall(p,html)
for each in iplist:
print(each)
page.close()
if __name__ == '__main__':
url = "http://cn-proxy.com"
get(open_url(url))
这种问题多数情况是你的正则表达式没写正确,请多琢磨一下你的正则表达式! Will_M 发表于 2018-9-12 23:33
这种问题多数情况是你的正则表达式没写正确,请多琢磨一下你的正则表达式!
可是我的正则表达式是抄小甲鱼的耶,他的成功了{:5_100:} 我也是的,不知道什么原因{:5_99:}
页:
[1]