使用python爬取猫眼电影、房王、股吧论坛、百度翻译、有道翻译、高德天气、华夏基金、扇贝单词、糗事百科(股吧论坛)

'''
翻页获取股吧数据
http://guba.eastmoney.com/
获取10页信息,然后放到指定文件夹中
'''
'''
爬取板块:国产芯片
思路:
    找规律
        第一页:http://so.eastmoney.com/web/s?keyword=%E5%9B%BD%E4%BA%A7%E8%8A%AF%E7%89%87
        第二页:http://so.eastmoney.com/web/s?keyword=%E5%9B%BD%E4%BA%A7%E8%8A%AF%E7%89%87&pageindex=2
        第三页:http://so.eastmoney.com/web/s?keyword=%E5%9B%BD%E4%BA%A7%E8%8A%AF%E7%89%87&pageindex=3
'''
import requests,os

def guba(pageindex):
    base_url = 'http://so.eastmoney.com/web/s?'
    # base_url = 'http://so.eastmoney.com/web/s?keyword=%E5%9B%BD%E4%BA%A7%E8%8A%AF%E7%89%87&pageindex=4'
    params = {
        'keyword': '%E5%9B%BD%E4%BA%A7%E8%8A%AF%E7%89%87',
    }
    path = './guba/'+pageindex+'/'
    if not os.path.exists(path):
        os.makedirs(path)

    for page in range(1,11):
        print(f'——————————————开始下载第{page}页——————————————')
        params['pageindex'] = str(page)
        file_path = path + str(page) +'.html'
        print(requests.get(base_url,params=params).url)
        with open(file_path,'w',encoding='utf-8')as f :
            f.write(requests.get(base_url,params=params).text)

    print('下载完成')


if __name__ == '__main__':
    pageindex = input('请输入文件夹名称')
    guba(pageindex)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值