python使用requests模块实现爬取电影天堂最新电影信息
作者:理想何需三旬 时间:2021-02-21 22:44:44
requests是一个很实用的Python HTTP客户端库,编写爬虫和测试服务器响应数据时经常会用到。可以说,Requests 完全满足如今网络的需求。本文重点给大家介绍python使用requests模块实现爬取电影天堂最新电影信息,具体内容如下所示:
在抓取网络数据的时候,有时会用正则对结构化的数据进行提取,比如 href="https://www.1234.com"等。python的re模块的findall()函数会返回一个所有匹配到的内容的列表,在将数据存入数据库时,列表数据类型是不被允许的,而是需要将其转换为元组形式。下面看下,str/list/tuple三者之间怎么相互转换。
class forDatas:
def __init__(self):
pass
def str_list_tuple(self):
s = 'abcde12345'
print('s:', s, type(s))
# str to list
l = list(s)
print('l:', l, type(l))
# str to tuple
t = tuple(s)
print('t:', t, type(t))
# str转化为list/tuple,直接进行转换即可
# 由list/tuple转换为str,则需要借助join()函数来实现
# list to str
s1 = ''.join(l)
print('s1:', s1, type(s1))
# tuple to str
s2 = ''.join(t)
print('s2:', s2, type(s2))
str转化为list/tuple,直接进行转换即可。而由list/tuple转换为str,则需要借助join()函数来实现。join()函数是这样描述的:
"""
S.join(iterable) -> str
Return a string which is the concatenation of the strings in the
iterable. The separator between elements is S.
"""
join()函数使用时,传入一个可迭代对象,返回一个可迭代的字符串,该字符串元素之间的分隔符是“S”。
传入一个可迭代对象,可以使list,tuple,也可以是str。
s = 'asdf1234'
sss = '@'.join(s)
print(type(sss), sss)
总结
以上所述是小编给大家介绍的python使用requests模块实现爬取电影天堂最新电影信息网站的支持!
来源:https://www.cnblogs.com/n1celll/p/10628078.html
标签:python,requests,模块
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Dreamweaver快速编辑网页标签
2009-05-29 18:35:00
![](https://img.aspxhome.com/file/UploadPic/20072/200723113549405s.jpg)
很酷的JQuery Solar System
2007-12-15 08:09:00
![](https://img.aspxhome.com/file/UploadPic/200712/15/200712158138849s.png)
Golang依赖注入工具digo的使用详解
2023-08-27 13:00:43
js对象基础实例分析
2023-09-03 12:07:56
如何随机显示图片计数器?
2010-05-16 15:21:00
YUI学习笔记(3)
2009-01-21 16:24:00
Go语言sort包函数使用示例
2023-10-15 03:29:59
PHP get_html_translation_table()函数用法讲解
2023-06-05 18:36:00
![](https://img.aspxhome.com/file/2023/7/55387_0s.png)
javascript阻止事件冒泡和浏览器的默认行为
2007-12-28 13:13:00
JavaScript模板解析演示实例
2009-10-19 23:16:00
用FrontPage200八步快速建站
2008-09-17 10:52:00
![](https://img.aspxhome.com/file/UploadPic/200810/17/20081017105646475.jpg)
python中的实例方法、静态方法、类方法、类变量和实例变量浅析
2021-11-06 01:52:14
Python基于time模块求程序运行时间的方法
2023-07-27 15:59:03
![](https://img.aspxhome.com/file/2023/0/61220_0s.png)
详解bootstrap导航栏.nav与.navbar区别
2023-08-15 19:18:42
![](https://img.aspxhome.com/file/2023/7/56077_0s.png)
精美漂亮的php分页类代码
2023-11-22 08:28:09
python列表操作之extend和append的区别实例分析
2023-08-02 15:14:30
深入透析样式表滤镜(下)
2011-06-14 09:49:19
python 负数取模运算实例
2022-06-17 00:50:49
![](https://img.aspxhome.com/file/2023/0/72760_0s.jpg)
python交互式图形编程实例(一)
2022-11-12 14:44:53
python带你探寻WSGI Application原理
2022-03-25 19:35:55
![](https://img.aspxhome.com/file/2023/2/77652_0s.jpg)