1 Star 0 Fork 0

dzc/Python-1

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
psunotify.py 1.10 KB
一键复制 编辑 原始数据 按行查看 历史
Jinyoung_Han 提交于 2018-12-13 01:01 +08:00 . Merge branch 'master' into master
from __future__ import print_function
import mechanize
import re
import urllib2
from random import *
br=mechanize.Browser()
br.addheaders = [('User-Agent','Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36')]
br.set_handle_robots(False)
#For page exploration
page=raw_input('Enter Page No:')
#print type(page)
p=urllib2.Request('https://www.google.co.in/search?q=gate+psu+2017+ext:pdf&start='+page)
ht=br.open(p)
text='<cite\sclass="_Rm">(.+?)</cite>'
patt=re.compile(text)
h=ht.read()
urls=re.findall(patt,h)
int=0
while int<len(urls):
urls[int]=urls[int].replace("<b>","")
urls[int]=urls[int].replace("</b>","")
int=int+1
print(urls)
for url in urls:
try:
temp=url.split("/")
q=temp[len(temp)-1]
if "http" in url:
r=urllib2.urlopen(url)
else:
r=urllib2.urlopen("http://"+url)
file=open('psu2'+q+'.pdf','wb')
file.write(r.read())
file.close()
print("Done")
except urllib2.URLError as e:
print("Sorry there exists a problem with this URL Please Download this Manually "+str(url))
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sdredboy/Python-1.git
git@gitee.com:sdredboy/Python-1.git
sdredboy
Python-1
Python-1
master

搜索帮助