CD84380973 发表于 2020-3-31 20:16:49

55讲动动手3道题答案报错

错误类型都是TypeError: __init__() got an unexpected keyword argument 'strict'

zltzlt 发表于 2020-3-31 20:18:09

发代码

张冯的小能豆 发表于 2020-3-31 20:22:10

代码在哪里

CD84380973 发表于 2020-3-31 21:10:36

张冯的小能豆 发表于 2020-3-31 20:22
代码在哪里

import urllib.request
import re
from bs4 import BeautifulSoup

def main():
    url = "http://baike.baidu.com/view/284853.htm"
    response = urllib.request.urlopen(url)
    html = response.read()
    soup = BeautifulSoup(html, "html.parser") # 使用 Python 默认的解析器
   
    for each in soup.find_all(href=re.compile("view")):
      print(each.text, "->", ''.join(["http://baike.baidu.com", each["href"]]))
      # 上边用 join() 不用 + 直接拼接,是因为 join() 被证明执行效率要高很多

if __name__ == "__main__":
    main()

十月故里 发表于 2020-4-1 16:28:02

我运行正常啊,没报错
恐龙百科 -> http://baike.baidu.com/wikicategory/view?categoryName=恐龙大全
多肉百科 -> http://baike.baidu.com/wikicategory/view?categoryName=多肉植物
锁定 -> http://baike.baidu.com/view/10812319.htm
页: [1]
查看完整版本: 55讲动动手3道题答案报错