Home > Backend Development > PHP Tutorial > javascript - Python逐行读取txt中的url文件并进行爬虫

javascript - Python逐行读取txt中的url文件并进行爬虫

WBOY
Release: 2016-06-06 20:11:35
Original
1432 people have browsed it

毕设项目需要爬取coursera的课程数据,已经把所有课程的url链接爬下来了,存在了txt中,一行是一个课程的url,现在想要获取每门课程的详细信息,如instructor,syllabus 和detail information这几项,但是都需要点进各个课程的网页链接中取爬取。码渣求大神指导一下,来段伪码就更好啦!thx

回复内容:

毕设项目需要爬取coursera的课程数据,已经把所有课程的url链接爬下来了,存在了txt中,一行是一个课程的url,现在想要获取每门课程的详细信息,如instructor,syllabus 和detail information这几项,但是都需要点进各个课程的网页链接中取爬取。码渣求大神指导一下,来段伪码就更好啦!thx

你好!不知道这是不是你想要的答案:

<code>f = open("coursera.txt","r")
urlList = f.readlines()
for url in urlList:
    r = requests.get(url)
    ''''''</code>
Copy after login

Good Luck ! ^_

如果是爬取coursera的课程数据,建议你用scrapy爬取,这样不需要提前抓取所有课程的url,只要写好匹配url就行。

scrapy教程 http://scrapy-chs.readthedocs.org/zh_CN/0.24/intro/tutorial.html
项目参考 https://github.com/Junnplus/OnlineJudgeCrawlerCore

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template