python爬虫---污言污语网站数据采集


代码:

import requests
from lxml import etree

headers = {
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36 Edg/96.0.1054.62"
}


def get_text():
    count = 0
    while True:
        with open("nihaowua.txt", "a") as file:
            resp = requests.get("https://www.nihaowua.com/", headers=headers, timeout=10).text
            html = etree.HTML(resp)
            content = html.xpath("//section/div/*/text()")[0]
            file.write(content + "\n")
            count += 1


get_text()

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM