Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
402 views
in Technique[技术] by (71.8m points)

python爬虫爬取网页的内容和网页源码不同?

imageimage
可以看到这里id为k_total的元素值不同,爬出来是1,网页源码是55。
附还未完成的代码:

import requests
from bs4 import BeautifulSoup
import re
head={
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36',
'Referer':'http://m.manhuaju.com/maoxian/zujienvyou/420624.html'
 }
baseurl=r'http://m.manhuaju.com/maoxian/zujienvyou/'
find_link=re.compile('<li><a href="(.*?)" target')
def process(url):
 r = requests.get(url=url, headers=head)
    soup = BeautifulSoup(r.content, 'html.parser')
    return soup
def askurl():
 soup=process(baseurl)
    url_eve=soup.find_all(name='ul',class_="Drama autoHeight")
    url_eve_2=''.join('%s'%id for id in url_eve)
    link=re.findall(find_link,url_eve_2)
    link_re = list(reversed(link))
    return link_re
def getdata():
 for i in range(1):
 result=(r"http://m.manhuaju.com"+askurl()[i])
        print(result)
 each_page=process(result)
        print(each_page)

getdata()

初学爬虫,希望大佬们不吝赐教,感谢。
PS:还有一个问题,这个网站的图片格式似乎被加密过,单爬取打不开,还请大佬们点拨如何解密。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

那个总数应是由js动态渲染的,这种页面可以:要么分析脚本,要么通过 selenium来抓取


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...