python爬虫源代码没有但检查

Python014

python爬虫源代码没有但检查,第1张

python爬虫源代码没有但检查可以通过5个步骤进行解决。

1、提取列车Code和No信息。

2、找到url规律,根据Code和No变化实现多个网页数据爬取。

3、使用PhantomJS模拟浏览器爬取源代码。

4、用bs4解析源代码,获取所需的途径站数据。

5、用csv库存储获得的数据。

import requests import parsel import threading,os import queue

class Thread(threading.Thread): def init (self,queue,path): threading.Thread. init (self) self.queue = queue self.path = path

def download_novel(url, path): res = get_response(url) selctor = parsel.Selector(res) title = selctor.css('.bookname >h1::text').get() print(title) content = ' '.join(selctor.css('#content::text').getall()) # 使用join方法改变内容; with open( path + title + ".txt","w",encoding='utf-8') as f: f.write(content) print(title,'保存成功!') f.close()

def get_response(url): # 获得网站源码; response = requests.get(url) response.encoding = 'utf-8' return response.text

if name == ' main ': # 函数入口 url = str(input('请输入你要下载小说的url:')) response = get_response(url) sel = parsel.Selector(response) novelname = sel.css('#info >h1::text').get() urllist = sel.css('.box_con p dl dd a::attr(href)').getall() queue = queue.Queue() path = './{}/'.format(novelname)