2
wiki
from url.requst import urlopen
from bs4 import BeautifulSoup
import re
#获取网页源代码
resp= urlopen("https://en.wikipedia.org/wiki/Main_Page").read().decode("utf-8")
#解析?网页
soup = BeautifulSoup(resp."html.parse")
#获取所有以/wiki/开头的链接
urls = soup.findAll('a',href=re.compeil("^/wiki/"))
#获取链接内容
for uls in urls:
if not re.search("/.(jpg|JPG)$",url["href"])
print(url.get_text(),url["href"])
输出某个页面的全部href
专业人士如何改代码,代码不是抄出来的,是改出来的
导入模块
1.读取网页信息
2.对读取到的信息进行排版
3.对排版过的数据进行二次获取操作。
4.打印结果