python 爬虫(1)

教程:https://blog.csdn.net/c406495762/article/details/78123502 by Jack Cui

在做简单实例一时遇到的问题:

文本爬不下来,评论里说是网站用JS加载了。

改代码如下:

from bs4 import BeautifulSoup
from selenium import webdriver
if __name__ == '__main__':
    target = 'http://www.biqukan.com/1_1094/5403177.html'
    driver = webdriver.Chrome()
    req = driver.get(target)
    html = driver.page_source
    bf = BeautifulSoup(html, 'html.parser')
    texts = bf.find_all('div', class_='showtxt')
    print(texts[0].text.replace('\xa0'*8, '\n\n'))

需要下载安装selenium+webdriver

selenium+webdriver下载安装:https://www.cnblogs.com/technologylife/p/5829944.html

webdriver配置:https://blog.csdn.net/qq_40604853/article/details/81388078

你可能感兴趣的:(python)