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