Skip to content

Commit

Permalink
Merge pull request vansl#5 from xudong07/master
Browse files Browse the repository at this point in the history
全局的headers被意外修改后不可再用于获取页面
  • Loading branch information
vansl authored Feb 6, 2018
2 parents 8965fa9 + a634800 commit f525be2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.vscode/settings.json
.vscode/tasks.json
.vscode/launch.json
.vscode/extensions.json
8 changes: 5 additions & 3 deletions spider.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ def main(amount,firstIndex):
class Download(threading.Thread):
def __init__(self, urlMannager):
threading.Thread.__init__(self)
self.urlMannager=urlMannager
self.urlMannager=urlMannager
self.pic_headers = headers
self.pic_headers['Host'] = 'wx3.sinaimg.cn'

def download_Img(self,url):
isGif=re.match(r'(.*\.sinaimg\.cn\/)(\w+)(\/.+\.gif)',url)
Expand All @@ -157,8 +159,8 @@ def download_Img(self,url):
if not os.path.exists('img'):
os.mkdir('img')
with open ('img/'+str(len(os.listdir('./img')))+extensionName, 'wb') as f:
headers['Host']='wx3.sinaimg.cn'
f.write(requests.get(url,headers=headers).content)
# headers['Host']='wx3.sinaimg.cn'
f.write(requests.get(url,headers=self.pic_headers).content)
f.close()
L.release()

Expand Down

0 comments on commit f525be2

Please sign in to comment.