用.的方式运行会报错

dicoz

2 回复13 浏览

来自课程:Python爬虫从爪巴到爬

import requests
from bs4 import BeautifulSoup

#请求的地址
url = "http://www.gaokao.com/gkpic/"

#发起请求
resp = requests.get(url)

#拿到网页源代码
html = resp.content.decode("gbk")

#使用bs解析
soup = BeautifulSoup(html,"html.parser")

# print(html)

#通过. 的方式查找节点,同名的标签只能找到第一个
print(html.head)

老师,请问下为什么这个运行出来会报错?

报错行就是最后一行

全部回复(2)

  • dicoz 楼主 1 楼

    老师问题解决了,我自己弄明白了
  • SiKi学院老师007 2 楼

    OK哈

     

发表回复

登录后可以回复