1 Star 1 Fork 20

zhangpengju/电影资源站搜索核心代码

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
spider.py 2.27 KB
一键复制 编辑 原始数据 按行查看 历史
# -*- coding: utf-8 -*-
"""
Created on Mon May 27 14:18:44 2019
@author: Administrator
"""
import re
import requests
class Spider:
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36'
}
def get_html(self, url, encoding = None):
r = requests.get(url, headers = self.headers, timeout = 2)
if encoding == None:
r.encoding= r.apparent_encoding
else:
r.encoding = encoding
return r.text
def post_html(self, url, data, encoding = None):
r = requests.post(url, headers = self.headers, data = data, timeout = 2)
if encoding == None:
r.encoding= r.apparent_encoding
else:
r.encoding = encoding
return r.text
def get_info(self, url, encoding = None, **regex):#位置参数要在关键字参数之前
'''
{'name':'.*?', 'year':''}
'''
html = self.get_html(url)
for reg in regex:
regex[reg] = re.findall(regex[reg], html)
return regex
def post_info(self, url, data, encoding = None, **regex):
html = self.post_html(url, data, encoding = encoding)
for reg in regex:
regex[reg] = re.findall(regex[reg], html)
return regex
if __name__ == '__main__':
url = 'https://www.subo8988.com/?m=vod-detail-id-19246.html'
x = Spider()
info = x.get_info(url, jian_jie = '<div class="vodplayinfo">(.*?)</div>')
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhangpengju/movie_resource_station_search.git
git@gitee.com:zhangpengju/movie_resource_station_search.git
zhangpengju
movie_resource_station_search
电影资源站搜索核心代码
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385