先说一下任务,目前呢在网络上搜索我的世界 ID 的话,会发现 ne 那个搜到的大多都是好多年以前的内容了,比如说那张我记的好久好久好久以前就存在的 ID 对照图。
就是这张,影响深刻,但是实际上随着年份的增加,我的世界的版本更新还是蛮快的,一些新的内容在这上面就找不到了,所以就萌生了一个做 ID 对照的网站的想法,但是数据从哪来呢?答案当然是百度,通过百度的查询我发现了一个老外的 ID 站做的很不错,所以呢,目标就设定为他,使用 Python 爬虫将我需要的数据爬取下来。
withopen("mclist.txt", 'a', encoding='utf-8') as file_object: n = 1 for i inrange(0, length, 20): file_object.write((wenzi[i:i+20])) if n == 10: file_object.write('\n') n = 0 n += 1
for a inrange(2, 9): newurl = url + str(a) r = requests.get(newurl, headers=headers) neirong = r.text soup = BeautifulSoup(neirong, "lxml") wenzi = soup.table.get_text() length = len(wenzi)
withopen("mclist.txt", 'a', encoding='utf-8') as file_object: n = 1 for i inrange(0, length, 20): file_object.write((wenzi[i:i + 20])) if n == 10: file_object.write('\n') n = 0 n += 1
session = HTMLSession() url = "https://my.oschina.net/u/4798232" r = session.get(url)
for i inrange(1, 12): i = str(i) url_xpath = '//div[@id="newestBlogList"]/div[1]/div[' + i + ']/div/a' title = r.html.xpath(url_xpath, first=True).text link_xpath = url_xpath + '/@href' link = r.html.xpath(link_xpath, first=True) a = "原" if a notin title: print(title) print(link) else: print(title.replace(a, "")) print(link)