【实现】[抓取知网论文标题摘要] 终于能用Sublime直接编译运行python了,可是却无法导入bs4 | BeautifulSoup

本文封装的实例下载:https://download.csdn.net/download/qq_19741181/10279675py抓取知网论文摘要-----------------------------------------------------------文章主要参考:http://blog.csdn.net/Eastmount/article/details/78534119?loc...
摘要由CSDN通过智能技术生成

本文封装的实例下载:https://download.csdn.net/download/qq_19741181/10279675

py抓取知网论文摘要

-----------------------------------------------------------

文章主要参考:http://blog.csdn.net/Eastmount/article/details/78534119?locationNum=6&fps=1

-----------------------------------------------------------

(C:\ProgramData\Anaconda3) C:\Users\d>pip install --upgrade beautifulsoup4

Requirement already up-to-date: beautifulsoup4 in c:\programdata\anaconda3\lib\site-packages


(C:\ProgramData\Anaconda3) C:\Users\d>

----跟着网上升级试了试 :参考:http://blog.csdn.net/sinat_26599509/article/details/50609646------------------

>>> import time
>>> import re
>>> import urllib
>>> import bs4
>>> from bs4 import BeautifulSoup

>>> if __name__ == '__main__':
...   url = "http://search.cnki.net/Search.aspx?q=python&rank=relevant&cluster=all&val=&p=0"
...   content = urllib.urlopen(url).read()
...   soup = BeautifulSoup(content,"html.parser")
...   wz_tab = soup.find_all("div",class_="wz_tab")
...   num = 0
...   for tab in wz_tab:
...     title = tab.find("h3")
...     print(title.get_text())
...     urls = tab.find("h3").find_all("a")
...     flag = 0
...     for u in urls:
...       if flag==0:
...         print(u.get('href'))
...         flag += 1
...     abstract = tab.find(attrs={"class":"width715"}).get_text()
...     print(abstract)
...     other = tab.find(attrs={"class":"year-count"})
...     content = other.get_text().split("\n")
...     cb_from = other.find_all("span")
...     flag = 0
...     for u in cb_from:
...       if flag==0:
...         print(u.get("title"))
...         flag += 1
...     mode = re.compile(r'\d+\.?\d*')
...     number = mode.findall(content[0])
...     print(number[0])
...     mode = re.compile(r'\d+\.?\d*')
...     number = mode.findall(content[1])
...     if len(number)=&

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值