出不来结果,报错的同学,欢迎568032437@qq.com询问,我很愿意发给你这一课的代码。评论不能超过300字,贴不了代码。。。
2017-03-19
try:
with connection.cursor() as cursor:
sql = "insert into test(name,url) values (%s,%s)"
cursor.execute(sql,(url.get_text(),'https://en.wikipedia.org' + url['href']))
connection.commit()
finally:
connection.close()
with connection.cursor() as cursor:
sql = "insert into test(name,url) values (%s,%s)"
cursor.execute(sql,(url.get_text(),'https://en.wikipedia.org' + url['href']))
connection.commit()
finally:
connection.close()
2017-03-18
ImportError: cannot import name 'request' 报这个错的,请参考修改代码。
import urllib
resp = urllib.urlopen('http://www.baidu.com')
print (resp.read())
import urllib
resp = urllib.urlopen('http://www.baidu.com')
print (resp.read())
2017-03-17
使用的2.7版本
import urllib2
req=urllib2.Request("http://www.baidu.com")
req.add_header("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36")
response=urllib2.urlopen(req)
print (response.read())
import urllib2
req=urllib2.Request("http://www.baidu.com")
req.add_header("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36")
response=urllib2.urlopen(req)
print (response.read())
2017-03-12
Python2.7貌似没request,所以用以下的方法
import urllib
resp = urllib.urlopen('http://www.qq.com')
print(resp.read())
import urllib
resp = urllib.urlopen('http://www.qq.com')
print(resp.read())
2017-03-11