python3.0下载用什么浏览器_同样一个下载地址,用python爬虫爬取的种子文件大小为0,而用浏览器是可以正常下载下来的?...

博主遇到一个问题,在使用Python爬虫尝试下载网页中的种子文件时,下载后的文件大小为0。通过分析发现,当加入特定的请求头headers时,种子文件虽然能下载但内容为空;而如果不加headers,则下载的文件虽非0大小,但同样缺乏实际内容。目前寻求解决种子文件无法正确下载的方法,可能是headers构造不正确或者缺少某些关键信息。
摘要由CSDN通过智能技术生成

1.访问某个网页,用浏览器可以下载其中嵌入的种子文件,种子文件大小是正常的,用迅雷工具也可以正常下载,但是用python爬虫爬取,并且下载下来的数据大小为0?

2.这是我自己写的代码。

url = 'http://www.gawu88.space/thread-9431970-1-1.html'

headers = {

'Cookie':'__cfduid=d15f7eb39310b0301f07e1f744ca70a3d1526800937; _ga=GA1.2.942865751.1526800940; A8tI_2132_saltkey=njU69xqb; A8tI_2132_lastvisit=1526797339; A8tI_2132_adult_warn=1; A8tI_2132_auth=7d44BRr5TCxDGN9zYzcgtvgTYZzopZtEOJjzAO323fO%2BdvFoIjRzKH31yzmid2IjzmB9bQ5PLK%2B1iWLRV%2BnD6zp8PwkV; A8tI_2132_lastcheckfeed=7589318%7C1526800977; A8tI_2132_smile=2D1; A8tI_2132_atarget=1; _gid=GA1.2.849215201.1527331040; cus_cookie=5; A8tI_2132_adv_gid=18; A8tI_2132_self_unique_code=6357ea0d-3640-91bf-a290-cdc483f40ded; A8tI_2132_ignore_notice=1; __insp_wid=1484672786; __insp_nv=true; __insp_targlpu=aHR0cDovL3d3dy5nYXd1ODguc3BhY2UvcG9ydGFsLmh0bWw%3D; __insp_targlpt=6K665Z2b6Zeo5oi3X_adj_WQp_iuuuWdm1%2FmgKflkKfmiJDkurrorrrlnZs%3D; __insp_norec_sess=true; A8tI_2132_sign_close=1; A8tI_2132_notification_readed_ids=57457151; A8tI_2132_noticeTitle=1; A8tI_2132_notification_unread_tips=1527519801; A8tI_2132_credit_max_num=0; A8tI_2132_credit_remain_num=0; A8tI_2132_sendmail=1; A8tI_2132_st_t=7589318%7C1527520644%7C1dc26593f0230c7c6b43bde6c98103c9; A8tI_2132_forum_lastvisit=D_180_1526811032D_181_1527427919D_815_1527520227D_798_1527520644; A8tI_2132_visitedfid=798D815D181D307D791D216D11D180D142D27; A8tI_2132_ulastactivity=1527520644%7C0; A8tI_2132_self_uid=7589318; A8tI_2132_self_fid=798; A8tI_2132_st_p=7589318%7C1527520650%7C570a2893a0834543f205c6bc2090a236; A8tI_2132_viewid=tid_9478918; A8tI_2132_self_tid=9478918; A8tI_2132_lastact=1527520651%09misc.php%09seccode; A8tI_2132_seccode=129607798.bd627f2e523f8c47f4; __insp_slim=1527520653270',

'Host':'www.gawu88.space',

'Referer':'http://www.gawu88.space/forum-798-1.html',

'Accept-Encoding':'',

'User-Agent':'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36',

}

response = requests.get(url,headers=headers)

html = etree.HTML(response.text)

print(response.text)

hrefs ='http://www.gawu88.space/'+ html.xpath('//span[@style="white-space: nowrap"]/a/@href')[0]

req = requests.get(hrefs,headers=headers)

file_name = "f:/1.torrent"

with open(file_name,"wb") as f:

f.write(req.content)

f.close()

3.如果我不加入headers,虽然下载下来的种子数据不再为0,但是下载的种子文件是一个空文件,里面没有下载数据。

4.我想知道的是为什么不能够下载种子文件,有没有什么解决方法?还是我的请求头headers构造有问题?希望各位朋友能够帮忙解决一下。谢谢。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值