我是scrapy和python新手,我可以从URL获取详细信息,我想进入链接并下载所有文件(.htm和.txt)。在
我的代码
import scrapy
class legco(scrapy.Spider):
name = "sec_gov"
start_urls = ["https://www.sec.gov/cgi-bin/browse-edgar?company=&match=&CIK=&filenum=&State=&Country=&SIC=2834&owner=exclude&Find=Find+Companies&action=getcompany"]
def parse(self, response):
for link in response.xpath('//table[@summary="Results"]//td[@scope="row"]/a/@href').extract():
absoluteLink = response.urljoin(link)
yield scrapy.Request(url = absoluteLink, callback = self.parse_page)
def parse_page(self, response):
for links in response.xpath('//table[@summary="Results"]//a[@id="documentsbutton"]/@href').extract():
targetLink = response.urljoin(links)
yield {"links":targetLink}
我需要进入链接并下载所有以.htm和.txt结尾的文件。下面的代码不工作。。在
^{pr2}$有人能帮我吗?提前谢谢。在
请尝试以下操作将文件下载到桌面或脚本中提到的任何位置:
更清楚一点:您需要显式地指定
dirf = r"C:\Users\WCS\Desktop\Storage"
,其中C:\Users\WCS\Desktop
或者其他什么是您想要的位置。但是,脚本将自动创建Storage
文件夹来保存这些文件。在相关问题 更多 >
编程相关推荐