这是我正在使用的代码。
// Here the original `posts` object is not modified, and that we don't
// (though you can) repeatedly call `getPostMeta()` for the same post.
posts.map( p => {
// Get all the post's meta data.
let meta = getPostMeta( p.ID );
// Do something with `meta`.
console.log( meta.large_preview );
});
console.log( JSON.stringify( posts[0].meta ) ); // posts[0].meta = undefined
console.log( posts[0].post_parent, posts[0].menu_order ); // both still defined
// posts[0].meta wouldn't be undefined if of course posts[0] had a `meta` item,
// which was set in/via WordPress...
现在,当我尝试访问它时,我收到了此错误
from google import google
search_results = google.search("this is test", 3)
for result in search_results:
print(result.description)
会出现什么问题?
编辑:我不是在问替代方案,我只是问为什么会出现这个问题?什么是解决方案?答案 0 :(得分:1)
您可以使用请求python库在Google上搜索。按pip install requests
安装请求您可以使用Google搜索任何内容并使用Beautifulsoup
解析结果。通过代码搜索谷歌上的查询,然后使用BeautifulSoup
获取Google返回的网址。
import requests
import urllib
from bs4 import BeautifulSoup
query = 'any search term'
r = requests.get('https://www.google.com/search?q={}'.format(query))
soup = BeautifulSoup(r.text, "html.parser")
links = []
for item in soup.find_all('h3', attrs={'class' : 'r'}):
links.append(item.a['href'])
print(links)