Crawl Baidu academic: title, keywords, year, abstract, original link, author.

Crawl Baidu academic: title, keywords, year, abstract, original link, the author can also write on the notepad. (If you want to write in the notepad, remove the f comment) You can also import the database

在这里插入代码片


import requests
import openpyxl
import re
from bs4 import BeautifulSoup
from urllib.request import quote


search = input('请输入关键词:')
kwen = search.encode('UTF-8') #将汉字,用utf格式编码,赋值给gbkkw
#f = open('学术1.xls','w',encoding ='UTF-8') #创建txt格式文件,方便等会存储`

`#添加请求头,模拟浏览器正常访问,避免被反爬虫
headers={'user-agent':'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'}
for x in range(10): #想要爬取多少页数据
    url = 'http://xueshu.baidu.com/s?wd='+quote(kwen)+'&pn='+str(x*10)+'&tn=SE_baiduxueshu_c1gjeupa&ie=utf-8&sc_f_para=sc_tasktype%3D%7BfirstSimpleSearch%7D&sc_hit=1'
    res &#

Guess you like

Origin blog.csdn.net/jiahuiandxuehui/article/details/109535919