python-3.x – SyntaxError:语法无效:除了urllib2.HTTPError,e:

python-3.x – SyntaxError:语法无效:除了urllib2.HTTPError,e:,第1张

概述我试图通过关键字刮取这个xml页面的链接,但urllib2给我带来的错误,我无法解决 python3 … from bs4 import BeautifulSoupimport requestsimport smtplibimport urllib2from lxml import etreeurl = 'https://store.fabspy.com/sitemap_products 我试图通过关键字刮取这个xml页面的链接,但urllib2给我带来的错误,我无法解决 python3 …

@H_502_11@from bs4 import BeautifulSoupimport requestsimport smtplibimport urllib2from lxml import etreeurl = 'https://store.fabspy.com/sitemap_products_1.xml?from=5619742598&to=9172987078'hdr = {'User-Agent': 'Mozilla/5.0 (X11; linux x86_64) AppleWebKit/537.11 (KHTML,like Gecko) Chrome/23.0.1271.64 Safari/537.11','Accept': 'text/HTML,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8','Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3','Accept-EnCoding': 'none','Accept-Language': 'en-US,en;q=0.8','Connection': 'keep-alive'}proxIEs = {'https': '209.212.253.44'}req = urllib2.Request(url,headers=hdr,proxIEs=proxIEs)try: page = urllib2.urlopen(req)except urllib2.httpError as e: print(e.fp.read())content = page.read()def parse(self,response): try: print(response.status) print('???????????????????????????????????') if response.status == 200: self.driver.implicitly_wait(5) self.driver.get(response.url) print(response.url) print('!!!!!!!!!!!!!!!!!!!!') # DO STUFF except httplib.BadStatusline: passwhile True: soup = BeautifulSoup(a.context,'lxml') links = soup.find_all('loc') for link in links: if 'notonesite' and 'winter' in link.text: print(link.text) jake = link.text

我只是试图通过代理发送urllib请求,看看链接是否在站点地图上…

解决方法 urllib2在python3中不可用.你应该使用 urllib.errorurllib.request

@H_502_11@import urllib.requestimport urllib.error...req = (url,headers=hdr) # doesn't take a proxIEs argument though......try: page = urllib.request.urlopen(req)except urllib.error.httpError as e:...

…等等.但请注意,urllib.request.Request()不接受代理参数.有关代理处理,请参阅the documentation.

总结

以上是内存溢出为你收集整理的python-3.x – SyntaxError:语法无效:除了urllib2.HTTPError,e:全部内容,希望文章能够帮你解决python-3.x – SyntaxError:语法无效:除了urllib2.HTTPError,e:所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1193828.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存