猫史档案馆


【Python作品分享】用Python爬虫爬取电影信息【作品秀】

用户:всетоварывсетовары查看:0 回复:2 评论:0 创建时间:2023-08-28T14:44:45


【作品展示】

center_image

 

【作品介绍】

爬虫学的好

牢饭吃到饱

 

【作品源代码】

import requests
import re
import time
import csv
url = 'https://dytt89.com/'

header = {
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win喵; x喵) AppleWebKit/537.36 (KH喵L, like Gecko) Chrome/102.0.0.0 Safari/537.36'
}

resp = requests.get(url=url,headers=header)
resp.encoding = 'gb2312'
resp.close()

obj1 = re.compile(r"2023必看热片.*?
  
    (?P
      .*?)
    ",re.S) obj2 = re.compile(r" .*?)
    .*?

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
天伦之乐Dr-N天伦之乐Dr-N

import requests import re import time import csv url = ' https://dytt89.com/'
header = { 'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KH喵L, like Gecko) Chrome/102.0.0.0 Safari/537.36' }
resp = requests.get(url=url,headers=header) resp.encoding = 'gb2312' resp.close()
obj1 = re.compile(r"2023必看热片.*?<ul>(?P<ul>.*?)</ul>",re.S) obj2 = re.compile(r"<a href='(?P<href>.*?)'",re.S) obj3 = re.compile(r'◎片  名(?P<name>.*?)<br />.*?<td ' r'style="WORD-WRAP: break-word" bgcolor="#fdfddf"><a href="(?P<downurl>.*?)"',re.S)

ret1 = obj1.finditer(resp.text) for it in ret1: ul = it.group('ul') ret2 = obj2.finditer(ul) child_list = []
for itt in ret2: child_href = url + itt.group('href').strip('/') child_list.append(child_href)
resp_list = []
f = open('moive.csv',mode='w',encoding='utf-8') csvw = csv.writer(f) for href in child_list: child_resp = requests.get(href,headers=header) child_resp.encoding = 'gb2312' ret3 = obj3.search(child_resp.text) dic = ret3.groupdict() csvw.writerow(dic.values()) #把间隔时间改长一点,不然会被封 time.sleep(0.5) child_resp.close() print("over")

点赞0


评论


oWuGi7s6oWuGi7s6

的确呵呵

点赞0


评论