try: #有些div里面获取获取的内容是空的,这种就不要深度爬取了 if href != ‘’: if href.split('.')[-1] == 'html’: # 爬取到的href分为两种类型,分别进行时间提取 href = 'http://guba.eastmoney.com/o' + href response_deep = requests.get(url=href, headers=headers).text # 该请求获取的源代码与element不同,所以用正则提取时间 date_1 = re.findall(r'<div class="zwfbtime">(.*?)</div>', response_deep, re.S) # 将提取出来的时间进行清洗 date_2 = ‘’.join(date_1) date_3 = re.findall(r'发表于(.*?)\r', date_2) date = ''.join(date_3).strip().split(' ')[0]
时间: 2024-02-10 15:09:54 浏览: 29
在获取到每个帖子的链接之后,如果链接不为空,则进行深度爬取,即进入链接内部获取更多的信息。先判断链接的类型,如果是以“.html”结尾的,则认为该链接是帖子的链接。然后用requests发送请求,获取返回的源代码。因为该请求获取的源代码与之前的element不同,所以使用正则表达式提取帖子发布时间,并进行清洗,最后将其转换为标准格式(年-月-日)。
相关问题
在java中,这一句代码是什么意思:if (!lock.tryLock())
这行代码的意思是,如果无法获取一个锁,则执行if语句块中的内容。具体来说,`lock.tryLock()`尝试获取一个锁,如果获取成功,则返回`true`,否则返回`false`。`!`表示逻辑非,因此`!lock.tryLock()`表示如果无法获取锁,即`tryLock()`返回`false`,则执行if语句块中的内容。
except OSError as e: if e.errno != errno.EEXIST: raise
This code snippet is a try-except block that handles the OSError exception that may occur when trying to create a directory.
The code tries to create a directory, but if it already exists, it will raise an OSError with the error number errno.EEXIST (which means the directory already exists).
If the OSError has a different error number, it will be raised and handled by the calling function.
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)