爬取百度词条内链接

来源:互联网 发布:js清空input的value值 编辑:程序博客网 时间:2024/06/04 22:03
"""
Created on Tue Dec 19 15:23:28 2017


@author: Administrator
"""


import urllib.request
from bs4 import BeautifulSoup
import re


url = 'https://baike.baidu.com/item/%E7%BD%91%E7%BB%9C%E7%88%AC%E8%99%AB'
response = urllib.request.urlopen(url)
html = response.read()
soup = BeautifulSoup(html,"html.parser")
for each in soup.find_all(href=re.compile('item')):
    print(each.text,"->",''.join(["http://baike.baidu.com",each["href"]]))
原创粉丝点击