已采纳回答 / 大象的回忆
url_manager是python程序建立的模块,是个.py文件,而UrlManager是一个类,self.urls=url_manager.UrlManager()是指在url_manager模块中创建对象(类)UrlManager
2016-05-02
已采纳回答 / Haitao_biology
不是把"data-cid"当成其中一个属性来看就行了么,课程中不是有根据"href"属性来提取<a>标签的例子么,把"href"换成"data-cid"试试.如果目标页面的<li data-cid="x">有不定个,就外面套个while循环,循环到该第i个元素找不到为止
2016-05-02
最赞回答 / 孟欣会
<...code...>url_manager中的add_new_urls函数中的if里面的url丢s了应该为def add_new_urls(self,urls):#向url管理器中添加批量url if urls is None or len(urls)==0: return for url in urls:#通过循环一个一个添加 self.add_new_url(url)
2016-05-01
import urllib.request
#直接请求
response = urllib.request.urlopen("http://www.baidu.com")
#读取内容
cont = response.read()
print(cont)
#直接请求
response = urllib.request.urlopen("http://www.baidu.com")
#读取内容
cont = response.read()
print(cont)
2016-04-29
最新回答 / qq_莫默漠_03677669
#-*- coding: UTF-8 -*- from bs4 import BeautifulSoupimport rehtml_doc = """<html><head><title>The Dormouse's story</title></head><body><p class="title"><b>The Dormouse's story</b></p><p clas...
2016-04-28
Python3.5
第三种方法:
import urllib.request
import http.cookiejar
cj = http.cookiejar.CookieJar()
pro = urllib.request.HTTPCookieProcessor(cj)
opener = urllib.request.build_opener(pro)
urllib.request.install_opener(opener)
response = urllib.request.urlopen('http://www.baidu.com')
第三种方法:
import urllib.request
import http.cookiejar
cj = http.cookiejar.CookieJar()
pro = urllib.request.HTTPCookieProcessor(cj)
opener = urllib.request.build_opener(pro)
urllib.request.install_opener(opener)
response = urllib.request.urlopen('http://www.baidu.com')
2016-04-28
Python3.5
第二种方法:
In [14]: import urllib.request
In [15]: request = urllib.request.Request('http://www.baidu.com')
In [16]: urllib.request.data = ('a','1')
In [17]: request.add_header('User_Agent','Mozilla/5.0')
In [18]: response = urllib.request.urlopen(request)
第二种方法:
In [14]: import urllib.request
In [15]: request = urllib.request.Request('http://www.baidu.com')
In [16]: urllib.request.data = ('a','1')
In [17]: request.add_header('User_Agent','Mozilla/5.0')
In [18]: response = urllib.request.urlopen(request)
2016-04-28
Python3.5
第一种方法:
In [8]: import urllib.request
In [9]: response = urllib.request.urlopen('http://www.baidu.com')
In [10]: print(response.getcode())
200
In [11]: cont = response.read()
第一种方法:
In [8]: import urllib.request
In [9]: response = urllib.request.urlopen('http://www.baidu.com')
In [10]: print(response.getcode())
200
In [11]: cont = response.read()
2016-04-28