1

import requests,csv
headers={"User-Agent": '''Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36'''}
url1="https://www.jianshu.com/asimov/books?page="
url2="&count=12&category_id=284"


infs=[]
for i in range(5):
    geturl=url1+str(i*1)+url2
    reponse=requests.get(geturl,headers=headers)
    strs = reponse.json()
    films=strs["books"]
    for film in films:
        title=film["name"]
        score=film["categories"]
        infs.append([title,score])
with open ("D://电影信息3.csv","w+",encoding="utf-8",newline="") as f:
    writer=csv.writer(f)
    writer.writerows(infs)
    print(geturl)

from bs4 import BeautifulSoup
import requests,csv
url = 'https://movie.douban.com/review/best/'
headers={"User-Agent":"Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Mobile Safari/537.36" }

r = requests.get(url,headers = headers).text
soup = BeautifulSoup(r,'lxml')
divs = soup.findAll('div',{'class':'main review-item'})
rows = []
for div in divs:
    head = div.find('h2').text
    body = div.find('div',{'class':'short-content'}).text
    rows.append([head,body])
with open('spiderdemo3.csv','w+',encoding='utf-8',newline='') as f:
    w = csv.writer(f)
    w.writerow(['head','body'])
    w.writerows(rows)
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值