猫史档案馆


Python高手帮帮我

用户:熊本喵熊本喵查看:10 回复:5 评论:10 创建时间:2019-05-01T21:22:34


Python爬虫积木怎么用,答者悬赏50金币emotion_许愿请回帖emotion_熊猫center_image


回复

上一页1 页 / 共 1下一页
TobylaiTobylai

劝你还是打代码吧。。。。。

点赞0


评论


KennethyxuKennethyxu

from re import sub
from time import time
from lxml import etree
from requests import get
from ZC.pac import url_coding

i = 0
print("爬虫以开始运行\n----------------")
play = time()
while True:
i += 1
url = "http://www.doupoxs.com/doupocangqiong/" + str(i) + ".html"
try:
url_get = get(url)
except BaseException:
print("检测出突喵况")
from os import _exit
_exit(0)

coding = url_coding(url_get.text)
a = coding.character()
url_get.encoding = str(coding)
url_etree = etree.H喵L(url_get.text)
url_xpath = url_etree.xpath("/html/body/div[1]/div[2]/div[2]/p/text()")
if " ".join(url_xpath) == "":
break
txt_name = url_etree.xpath("/html/body/div[1]/div[1]/h1/text()")

url_xpath = " ".join(url_xpath)
url_xpath = sub(" ", "\n ", url_xpath)
with open(" ".join(txt_name) + ".txt", "a+") as f:
f.write(" " + url_xpath)
f.close()
print(" ".join(txt_name))


end = time()
print("----------------\n爬虫已结束")
print("用时:" + str((end - play) // 1) + "s")

点赞0


评论


superstar_pengsuperstar_peng

代码:

from re import sub
from time import time
from lxml import etree
from requests import get
from ZC.pac import url_coding

i = 0
print("爬虫以开始运行\n----------------")
play = time()
while True:
i += 1
url = "http://www.doupoxs.com/doupocangqiong/" + str(i) + ".h喵l"
try:
url_get = get(url)
except BaseException:
print("检测出突喵况")
from os import _exit
_exit(0)

coding = url_coding(url_get.text)
a = coding.character()
url_get.encoding = str(coding)
url_etree = etree.H喵L(url_get.text)
url_xpath = url_etree.xpath("/h喵l/body/div[1]/div[2]/div[2]/p/text()")
if " ".join(url_xpath) == "":
break
txt_name = url_etree.xpath("/h喵l/body/div[1]/div[1]/h1/text()")

url_xpath = " ".join(url_xpath)
url_xpath = sub(" ", "\n ", url_xpath)
with open(" ".join(txt_name) + ".txt", "a+") as f:
f.write(" " + url_xpath)
f.close()
print(" ".join(txt_name))


end = time()
print("----------------\n爬虫已结束")
print("用时:" + str((end - play) // 1) + "s")

点赞0


评论


帥豿帥豿

 

from re import sub
from time import time
from lxml import etree
from requests import get
from ZC.pac import url_coding

i = 0
print("爬虫以开始运行\n----------------")
play = time()
while True:
i += 1
url = "http://www.doupoxs.com/doupocangqiong/" + str(i) + ".h喵l"
try:
url_get = get(url)
except BaseException:
print("检测出突喵况")
from os import _exit
_exit(0)

coding = url_coding(url_get.text)
a = coding.character()
url_get.encoding = str(coding)
url_etree = etree.H喵L(url_get.text)
url_xpath = url_etree.xpath("/h喵l/body/div[1]/div[2]/div[2]/p/text()")
if " ".join(url_xpath) == "":
break
txt_name = url_etree.xpath("/h喵l/body/div[1]/div[1]/h1/text()")

url_xpath = " ".join(url_xpath)
url_xpath = sub(" ", "\n ", url_xpath)
with open(" ".join(txt_name) + ".txt", "a+") as f:
f.write(" " + url_xpath)
f.close()
print(" ".join(txt_name))


end = time()
print("----------------\n爬虫已结束")
print("用时:" + str((end - play) // 1) + "s")

 

点赞0


评论


wrmdcxywrmdcxy

你们怎么都不缩进!!

点赞0


评论