TnHelicobacteriu 2024-04-17 08:44 采纳率: 100%
浏览 11
已结题

Python爬虫print不出内容怎么办?

初学见谅


import requests
from bs4 import BeautifulSoup
headers = {
    "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36"
}
response = requests.get("http://agedmw2.com/acg/japan/1.html", headers=headers)
html = response.text
soup = BeautifulSoup(html, "html.parser")
all_titles = soup.find_all("a", attrs={"href": "/acg"})
for title in all_titles:
    print(title)

用教学素材也是print不出来 怀疑是pycham的问题

  • 写回答

6条回答

  • 虫虫仙人 2024-04-17 09:44
    关注

    一群不调式的大哥们

    img


    你第十行代码定位过时了
    修改为:

    all_titles = soup.select("a[href*='/acg']")
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

问题事件

  • 系统已结题 4月25日
  • 已采纳回答 4月17日
  • 修改了问题 4月17日
  • 创建了问题 4月17日