3

Python爬虫编程思想(153):使用Scrapy抓取数据,抓取多个Url

 1 year ago
source link: https://blog.csdn.net/nokiaguy/article/details/125506849
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Python爬虫编程思想(153):使用Scrapy抓取数据,抓取多个Url

        在前面的案例中都是只抓取了一个Url对应的页面,但在实际应用中,通常需要抓取多个Url,在爬虫类的start_urls变量中添加多个Url,运行爬虫时就会抓取start_urls变量中所有的Url。下面的代码在start_urls变量中添加了2个Url,运行MultiUrlSpider爬虫后,就会抓取这两个Url对应的页面。

        下面的例子通过一个文本文件(urls.txt)提供多个Url,并在爬虫类中读取urls.txt文件中的内容,然后将读取的多个Url存入start_urls变量中。最后会抓取urls.txt文件中所有的Url对应的页面,并输出页面的博文数(本例提供的Url是geekori.com的博文列表页面,如果读者使用其他的Url,需要修改分析页面的逻辑代码)。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK