异步加载网站爬虫

from bs4 import BeautifulSoup
import requests
import time
headers={
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.75 Safari/537.36',
    'cookie':'_gat=1; gr_user_id=878a8f9c-aaad-4d7d-9341-8bb6d87828bc; _knewone_v2_session=eWJpdE5RTXZkbWxLU3FNalBZZk9lM09kSmE1My8vNUJvRCtCaDBpNXNLWm12dklxZ1NyWHd2Q2FEay9UNEV2WEVUS1V2Y1FQTVRrNlY3SlZPM2FidWhFQmhGOEZFd2U0NGpxT0xXall0bGpvMmVaTm00NEdraGFxTzBIUGdyeDkxbkNXQ1FkVWhaQzRrSzFESDM3Q1gwS3ZoSVd0QlFZRm90WGIybW9qb05jb3RsQ2ZwamlWYm9rU2U2MmVubDluLS1seXN2RXdjVzU1TGo4cFo2Zm1XdCtBPT0%3D--e90fa3ccbe2e3743ebe62ecf131580888682c9c9; _ga=GA1.2.1501286034.1482382737; Hm_lvt_b44696b80ba45a90a23982e53f8347d0=1482382738; Hm_lpvt_b44696b80ba45a90a23982e53f8347d0=1482382798; gr_session_id_e7b7e334c98d4530928513e7439f9ed2=184b0ab0-6d68-4a9d-87e8-8c2bf46fe653'
}

url='https://knewone.com/discover?page='



def get_page(url,data=None):
    wb_data=requests.get(url,headers=headers)
    soup=BeautifulSoup(wb_data.text,'lxml')
    titles=soup.select('section.content > h4 > a')
    links=soup.select('section.content > h4 > a')
    imgs=soup.select('a.cover-inner > img')


    if data==None:
        for img,title,link in zip(imgs,titles,links):
            data={
                'img':img.get('src'),
                'title':title.get('title'),
                'link':link.get('href')
            }
            print(data)


def get_more_page(start,end):
    for one in range(start,end):
        get_page(url+str(one))
        #time.sleep(1)


get_more_page(1,30)

转载于:https://www.cnblogs.com/lhfen/p/6211001.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值