Git Product home page Git Product logo

Comments (4)

crossin avatar crossin commented on August 22, 2024

在代码里加上输出,把请求的页面和拿到的结果输出来看
如果是后面的页面,是需要加上登录后的cookie才能拿到的,注释里有说

from snippet.

mugglejohnny avatar mugglejohnny commented on August 22, 2024

我的输入为:
import requests as rq
from bs4 import BeautifulSoup
import time
posts = []
h = {
'referer': 'https://bbs.hupu.com/bxj-postdate-1',
'user-agent': 'Mozilla/5.0 Chrome/66.0',
'cookie':"Hm_lpvt_39fc58a7ab8a311f2f6ca4dc1222a96e", # 添加你的cookie,否则只能抓前几十页
}
for i in range(1, 160):
print(i)
url = 'https://bbs.hupu.com/bxj-postdate-' + str(i)
r=rq.get(url, headers= h)
r.encoding='utf8'
print(r.text)
soup=BeautifulSoup(r.text, 'lxml')
lis = soup.find(class_="show-list").find_all('li')

for li in lis:
    title = li.a.text.lower()
    if '吴' in title or '凡' in title or 'skr' in title or 'diss' in title or 'rap' in title or 'hiphop' in title or '嘻哈' in title or 'wyf' in title or 'cris' in title or '51' in title:
        p = int(li.a.get('href').strip('/.html'))
        r, v = li.find(class_='ansour').text.split('/')
        r = int(r.strip())
        v = int(v.strip())
        Post.create(pid=p, title=title, count_reply=r, count_view=v)

输出为:
1
2
3
4
5
6
7
8
9
10
11
Traceback (most recent call last):

File "", line 18, in
lis = soup.find(class_="show-list").find_all('li')

AttributeError: 'NoneType' object has no attribute 'find_all'

from snippet.

mugglejohnny avatar mugglejohnny commented on August 22, 2024

还有一个小问题是:
line = ec.Line('时间统计', width=1000)
然后报错说ec没有define

from snippet.

mugglejohnny avatar mugglejohnny commented on August 22, 2024

您好 第一个问题已经解决了,
第二个问题line = ec.Line('时间统计', width=1000)中,
ec报错没有定义,老师可以帮忙解决一下吗?

from snippet.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.