吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 2877|回复: 10
收起左侧

[Python 转载] 帮朋友爬取的言情小说,名字叫《唱尽三生情》。

[复制链接]
mo_fan 发表于 2020-3-30 20:09
[Python] 纯文本查看 复制代码
import requests
from lxml import etree
# from bs4 import BeautifulSoup
import random
def main():
    header = {"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Safari/537.36"}

    all_ids_list = []
    url = "http://t.11jsq.com/index.php/api/entry?method=proxyServer.generate_api_url&packid=1&fa=0&fetch_key=&groupid=0&qty=10&time=1&pro=&city=&port=1&format=html&ss=5&css=&dt=1&specialTxt=3&specialJson=&usertype=15"
    r = requests.get(url=url, headers=header)
    r.encoding = r.apparent_encoding
    page_text = r.text
    tree = etree.HTML(page_text)
    body_list = tree.xpath("//body//text()")
    for id in body_list:
        dic = {"https": id}
        all_ids_list.append(dic)

    url = "https://www.63xs.com/book/161/161082/"
    page_text = requests.get(url = url,headers = header,timeout = 30).text
    tree = etree.HTML(page_text)
    dd_list = tree.xpath("//*[@id='list']/dl")
    with open("sanshengqing.txt", "w", encoding="utf-8")as fp:
        for dd in dd_list[1:]:
            title = dd.xpath("./a/text()")[0]
            detail_url ="https://www.63xs.com"+ dd.xpath("./a/@href")[0]
            detail__text = requests.get(detail_url,headers = header,proxies=random.choice(all_ids_list),timeout = 30).text
            tree = etree.HTML(detail__text)
            detail = tree.xpath("//*[@id='wrapper']/div[5]/div/div[3]/text()")

            fp.write(title+":"+detail+"\n")
            print(dd,"爬取成功")
    print(dd_list)
if __name__ == "__main__":
    main()

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

twl2018 发表于 2020-3-30 21:11
楼主大好人呀
poejie20200214 发表于 2020-3-30 21:15
ycy0536 发表于 2020-3-30 21:16
crc123 发表于 2020-3-30 21:18
Element dl at 0x3a73c38
致远英才 发表于 2020-3-30 21:24
谢谢了,学习了!
taozididi 发表于 2020-3-30 21:27
感谢楼主分享  瞧瞧
二诗的Adidas 发表于 2020-3-30 22:24
弱弱的问一句晋江可以吗
ll996075dd 发表于 2020-3-31 07:52
楼主大好人啊,带走研究代码去了
hshcompass 发表于 2020-3-31 19:48
运行报错。显示:
[<Element dl at 0x1739b152f00>]
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-17 04:37

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表