ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

学习爬虫参考

2021-10-31 17:05:23  阅读:175  来源: 互联网

标签:box info 参考 text list 爬虫 学习 str find


【爬虫教程】吐血整理,最详细的爬虫入门教程~ - AwesomeTang - 博客园 (cnblogs.com)

(3条消息) 大数据之如何利用爬虫爬取数据做分析_litao0942051021的博客-CSDN博客_爬虫爬取数据

#!/usr/bin/python
from typing import Counter
import requests                                         #导入所需要的爬虫模块
from bs4 import BeautifulSoup as bs
from requests import status_codes 

#获取数据浏览权限
headers ={"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36 Edg/95.0.1020.40"}
#爬取目标网址
url = "https://www.douyu.com/directory/all"

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

#print(r.text)
#p0rint(r.status_code)                                 #测试代码

html = r.text
html_tree = bs(html,"html.parser")                     #源数据解析

#print (html_tree)                                     #测试代码

info_list= html_tree.find("div",{"class":"layout-Module-container layout-Cover ListContent"})                       #定位All
#print(info_list.text)

#label_list= html_tree.find("div",{"class":"layout-Module-filter-list"})              #定位标签
#print(label_list.text)

#host_list=info_list.find_all('li')
#print(host_list.text)

info_file_data = open("C:\\Users\\13500\\Desktop\\file_data.txt","w")
info_file_data.write

box_list = info_list.find_all("li")    #在大目录中找目标条款
for box in box_list:
    box_name=box.find("h2",{"class":"DyListCover-user"})
    #box_hotIcon=box.find("span",{"class":"DyListCover-hot"})     #报错
    box_type = box.find("span",{"class":"DyListCover-zone"})
    box_illusion=box.find("h3",{"class":"DyListCover-intro"})
   #info_file_data.write(box_name.text+","+box_type.text+","+box_illusion.text+"\n")
    
    print(box_name.text+"\n"+box_type.text+"\n"+box_illusion.text+"\n"+box_hotIcon)
     #info_file_data.write(str(box_name)+","+str(box_hotIcon)+","+str(box_type)+","+str(box_illusion)+"\n")
    #info_file_data.write(str(box_name)+","+str(box_hotIcon)+","+str(box_type)+","+str(box_illusion)+"\n")

标签:box,info,参考,text,list,爬虫,学习,str,find
来源: https://blog.csdn.net/lakCSDN/article/details/121066484

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有