{
‘User-Agent’: 'Mozilla/5.0 (Windows NT 6.2) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.12 ’
‘Safari/535.11’},
{‘User-Agent’: ‘Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)’},
{‘User-Agent’: ‘Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:40.0) Gecko/20100101 Firefox/40.0’},
{
‘User-Agent’: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu ’
‘Chromium/44.0.2403.89 Chrome/44.0.2403.89 Safari/537.36’}]
file_path = “…\Files\Books”
def Parse_Page(self):
req = Request(self.url+str(self.page_num * 25), headers=random.choice(self.headers))
page = urlopen(req).read()
bsObj = BeautifulSoup(page, “html.parser”)
books_items = bsObj.find_all(“a”)
for item in books_items:
if ‘title’ in item.attrs:
self.Parse_Book(item.attrs[‘href’])
self.top_num += 1
self.page_num += 1
def Parse_Book(self, book_url):
print("book_url is: " + book_url)
try:
book_request = Request(book_url, headers=random.choice(self.headers))
book_html = urlopen(book_request).read()
book_bsObj = BeautifulSoup(book_html, “html.parser”)
book_title = book_bsObj.h1
book_info = book_bsObj.find(“div”, {“id”: “info”})
intro = book_bsObj.find_all(“div”, {“class”: “intro”})
if intro[0].get_text().find(“展开全部”) != -1:
book_intro = intro[1]
if intro[2].get_text().find(‘展开全部’) != -1:
author_intro = intro[3]
else:
author_intro = intro[2]
else:
book_intro = intro[0]
if intro[1].get_text().find(‘展开全部’) != -1:
author_intro = intro[2]
else:
author_intro = intro[1]
with open(self.file_path + ‘\Top’ + str(self.top_num) + ‘.txt’, ‘w’, errors=‘ignore’) as f:
f.write(book_title.get_text().strip() + ‘\n’)
info_text = book_info.get_text().split(’ ')
for info in info_text:
感谢每一个认真阅读我文章的人,看着粉丝一路的上涨和关注,礼尚往来总是要有的:
① 2000多本Python电子书(主流和经典的书籍应该都有了)
② Python标准库资料(最全中文版)
③ 项目源码(四五十个有趣且经典的练手项目及源码)
④ Python基础入门、爬虫、web开发、大数据分析方面的视频(适合小白学习)
⑤ Python学习路线图(告别不入流的学习)
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!