利用爬虫爬取网页数据import reimport requestsa=int(input('请输入起始页码'))b=int(input('请输入结束页码'))for page in range(a,b): url=f'http://www.netbian.com/index_{page}.htm' headers={ 'User-Agent':'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Mobile Safari/537.36 Edg/122.0.0.0' } response=requests.get(url=url,headers=headers) response.encoding=response.apparent_encoding #img_info=re.findall('',response.text) #正则表达式形式 img_info=re.findall(r'',response.text) #print(img_info) for link,title in img_info: link_url='http://www.netbian.com'+link response_1=requests.get(url=link_url,headers=headers) response_1.encoding=response_1.apparent_encoding#对响应先进行编码再进行解码 img_url=re.findall('target="_blank">声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!

下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态
评论