学了大概一个月爬虫了,看着人家爬东爬西的,自己也按捺不住终于写好了自己的爬虫,而且是福利哦。
这里我们主要用到了requests库,推荐大家用python 3.0+以上版本。
import urllib
import re
import requests
from requests.exceptions import RequestException
#这里是我们要爬的网址,为了示例只爬取20页
for j in range(1, 20):
url = 'http://www.qiubaichengren.com/' + str(j) + '.html'
#得到网页源代码
def get_page_index