因为最近也在学习python,爬虫和一点pandas的内容
刚好看到一篇博客,博客地址:https://blog.csdn.net/xiaoma_2018/article/details/108231658也是实现一样的内容的,只是使用的方式被我改了一下,我也是借鉴学习大佬的方法
我所使用到的库有lxml, urllib.request
代码如下
'''
导入所需要的库
'''
import urllib.request as ur
import lxml.etree as le
import pandas as pd
from config import EachSource,OUTPUT
url = 'https://blog.csdn.net/shine_a/article/list/2'
#得到博客所有内容
def get_blog(url):
req = ur.Request(
url=url,
headers={
'cookie':'c_session_id%3D10_1600923150109.901257%3Bc_sid%3D40c3e11ae0d6021f6f8323db1cc321a1%3Bc_segment%3D9%3Bc_first_ref%3Dwww.google.com.hk%3Bc_first_page%3Dhttps%253A%2F%2Fwww.csdn.net%2F%3Bc_ref%3Dhttps%253A%2F%2Fblog.csdn.net%2F%3Bc_page_id%3Ddefault%3B',
'User_Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gec