我正在使用BeautifulSoup来抓取一个网址,我有以下代码
import urllib
import urllib2
from BeautifulSoup import BeautifulSoup
url = "http://www.example.com/servlet/av/ResultTemplate=AVResult.html"
req = urllib2.Request(url)
response = urllib2.urlopen(req)
the_page = response.read()
soup = BeautifulSoup(the_page)
soup.findAll('td',attrs={'class':'empformbody'})
Run Code Online (Sandbox Code Playgroud)
现在在上面的代码中我们可以findAll用来获取与它们相关的标签和信息,但我想使用xpath.是否可以将xpath与BeautifulSoup一起使用?如果可能的话,有人可以给我一个示例代码,以便更有帮助吗?
我想以 XML 或 JSON 格式获取网络搜索结果,因此我尝试使用 REST API 自定义搜索引擎来执行此操作,但是当放置具有不同参数(如 cx、api 键、查询、范围)的任何 URL 时。我总是得到同样的错误:
您的客户无权从该服务器获取 URL /search?q=socer&hl=en&start=10&num=10&output=xml&client=950599431012-4mdbg8eqvb30cf6hamamq8sfihn71qku.apps.googleusercontent.com&cx=0066654167.googleusercontent.com&cx=00665417307bcccx=0066541012-4mdbg8eqvb30cf6hamamq8sfihn71 (客户端IP地址:105.190.4.82)
如果我的问题有其他解决方案,请向我展示。