鱼C论坛

 找回密码
 立即注册
查看: 2176|回复: 10

关于爬虫爬取信息的问题

[复制链接]
发表于 2019-10-18 12:30:38 From FishC Mobile | 显示全部楼层
你用什么来提取,把你的代码贴一下,才好回答
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-10-18 22:11:25 | 显示全部楼层
foreverc8 发表于 2019-10-18 13:26
这个跟我之前的差不太多,除了我多了个html.parser,而且也没有运行出来啊

我们根本无法爬取该网站的内容,看看根节点的内容如下

  1. import requests
  2. import bs4

  3. def get_url(url):
  4.     headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36'}
  5.    
  6.     res = requests.get(url,headers=headers)
  7.     return res

  8. def main():
  9.     url = 'https://www.opendota.com/heroes/1'
  10.     hero_list = []        
  11.     html = get_url(url)
  12.     html.encoding = 'utf-8'
  13.    
  14.     soup = bs4.BeautifulSoup(html.text,'html.parser')
  15.     targets = soup.html.body.div
  16.     print(targets.prettify())   
  17.    
  18.         
  19. if __name__ == '__main__':
  20.     main()
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-9-23 04:16

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表