用python爬取小說,python爬取晉江_爬蟲爬取晉江文學網總分榜

 2023-11-19 阅读 41 评论 0

摘要:一、目的 : 爬取晉江文學網總分榜 二、python爬取數據 三、爬取 用python爬取小說?在開始多出現了38號而且順序內容不準確 代碼: import requests from bs4 import BeautifulSoup import bs4 python爬蟲有什么用?url="http://www.jjwxc.net/topten.ph

一、目的 :

爬取晉江文學網總分榜

二、python爬取數據

三、爬取

1989769-20200503231140430-992073313.png

用python爬取小說?在開始多出現了38號而且順序內容不準確

代碼:

import requests

from bs4 import BeautifulSoup

import bs4

python爬蟲有什么用?url="http://www.jjwxc.net/topten.php?orderstr=7&t=0"

def getHtml(url):

r=requests.get(url)

r.raise_for_status()

r.encoding=r.apparent_encoding

爬蟲爬取數據、return r.text[26000:100000]

def fillList(html):

l1,l2 = [],[]

soup = BeautifulSoup(html,"html.parser")

for i in soup.find_all('a',"tooltip"):

python爬小說。l1.append(str(i.string))

for tag in soup.find_all('td',{"align":"center"}):

s=str(tag.string)

s.replace(" "," ")

l2.append(s)

python爬蟲教程,return l1,l2

def printList(l1,l2):

n1,n2 = len(l1),len(l2)

n=max(n1,n2)

for i in range(n):

python有什么用。print("第{}名:《{}》".format(i+1,l1[i]))

print("積分:{}".format(l2[i]))

print("")

def main():

html=getHtml(url)

用python爬取網站數據、l1,l2=fillList(html)

printList(l1,l2)

main()

1989769-20200503231204664-205732407.png

1989769-20200503231216433-871255079.png

這幾類數據我分不開,絕望

百度了一下就發現

1989769-20200503231511863-328999603.png

python爬蟲網站?內容網址:https://www.cnblogs.com/wangyongfengxiaokeai/p/11869595.html

而且好像height=‘23’和alig前后位置不同對結果也有影響

1989769-20200503231253181-831086467.png

又換了試就發現是紅框的問題,但是紅框內換了幾次代碼還是都不能完全分開,最后只有l2中為作品字數時可以完全帶進去,但是字數在這里沒有什么實際價值。

就只能做出排名

1989769-20200510232132056-1814349684.png

1989769-20200510232219591-1619824427.png

🆗

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://808629.com/186094.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 86后生记录生活 Inc. 保留所有权利。

底部版权信息