1、网页html代码如下:<html> <head> <title> This is a python demo page </title> </head> <body> <p> <b> The demo python introduces several python courses. </b> </p> <p> Python is a wonderful general-purpose programming language. You can learn Python from novice to professional by tracking the following courses: <a href="http://www.icourse163.org/course/BIT-268001" id="link1"> Basic Python </a> and <a href="http://www.icourse163.org/course/BIT-1001870001" id="link2"> Advanced Python </a> . </p> </body></html> (1)分析下面代码,补全代码。(6分) #引入bs4 #引入requests库import requests#爬取页面,将返回时封装到rr=requests.get("http://python123.io/ws/demo.html")#获取页面html信息demo=r.text#使用BeautifulSoup加载html print(soup.head) #结果1print(soup.head.contents) #结果2print(soup.title.parent) #结果3for parent in soup.a.parents: #结果4 if parent is None: print(parent) else: print(parent.name)print(soup.a.next_sibling) #结果5
1、网页html代码如下:
The demo python introduces several python courses.
Python is a wonderful general-purpose programming language. You can learn Python from novice to professional by tracking the following courses: Basic Python and Advanced Python .
(1)分析下面代码,补全代码。(6分) #引入bs4 #引入requests库import requests#爬取页面,将返回时封装到rr=requests.get("http://python123.io/ws/demo.html")#获取页面html信息demo=r.text#使用BeautifulSoup加载html print(soup.head) #结果1print(soup.head.contents) #结果2print(soup.title.parent) #结果3for parent in soup.a.parents: #结果4 if parent is None: print(parent) else: print(parent.name)print(soup.a.next_sibling) #结果5
发布时间:2024-09-05 17:22:52