码迷,mamicode.com
首页 > 其他好文 > 详细

lxml

时间:2018-06-08 19:32:38      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:x64   amp   firefox   XML   https   print   tree   style   main   

import urllib.request
from urllib import parse
from lxml import etree


class Tieba():
def __init__(self):
pass


def sendRequest(self,url,begin,end):
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0"}
for value in range(begin,end+1):
index = value - 1 * 50
u = "&pn="+str(index)
fullurl = url + u
print(fullurl)
# request = urllib.request.Request(fullurl,headers=headers)
# response = urllib.request.urlopen(request)
# print(response.read())

if __name__ == "__main__":
url = "https://tieba.baidu.com/f?"
keyword = input("请输入搜寻的关键字 >>")
beginPage = int(input("请输入起始页 >>"))
endPage = int(input("请输入结束页 >>"))
kw = parse.urlencode({"kw",keyword})
fullurl = url + kw
pattern = Tieba()
pattern.sendRequest(url,beginPage,endPage)

lxml

标签:x64   amp   firefox   XML   https   print   tree   style   main   

原文地址:https://www.cnblogs.com/angle90/p/9157069.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!