看有大佬已经发过可以写爬虫爬取本站,小弟喜欢看漫,但是苦于等级太低不能搜索,于是乎写了此代码爬取了本站精品动漫区一万多部漫画的名字和链接,代码很简单,直接在此贴出
import re
import pandas as pd
import requests
from lxml import html
from bs4 import BeautifulSoup
import cpca
txt = open('link_name', encoding='utf-8', mode='a ')
for j in range(0, 400):
url = 'http://23.225.255.86/forum/forum-565-{}.html'.format(j 2)
response = requests.get(url=url)
soup = BeautifulSoup(response.text, 'html.parser')
target_table = soup.find_all("table")[1]
rows = target_table.find_all("tbody")
for i in range(1, len(rows)):
span = rows.find('span').find('a')
txt.write(span.get('href') '\t' span.text.strip() '\n')
print('already', j)
txt.close()
结果展示:
thread-11089695-1-409.html [中文][OrangeMaru (JP06)] アイドルマスター シャイニーカラーズ 1-3[196MB/bd]【8.24中文新漫】
thread-11089442-1-409.html [中文][2021.08.24新漫][3D]催眠手机01-04[調教] [201MB/多空]
thread-11089440-1-409.html [中文][2021.08.24新漫][3D]无法原谅:欺骗的言语和脆弱的她01-02[丝袜] [237MB/多空]
thread-11089439-1-409.html [中文][2021.08.24新漫][3D]輕鬆短篇01-02[熟女] [259MB/多空]
thread-11089437-1-409.html [中文][2021.08.24新漫][3D]猎魔少女01-05 短篇[御姐] [329MB/多空]