- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我在 Windows Vista 64 位上运行 Scrapy.org 版本 2.7 64 位。我有以下代码,旨在从 Guardian 开放平台 API 中提取数据并使用一些 Scrapy 模块进行清理:
import requests
from scrapy.utils.markup import remove_tags
from scrapy.selector import Selector
def get_content():
api_url = 'http://beta.content.guardianapis.com/football/premierleague'
payload = {
'api-key': '',
'page-size': 10,
'show-editors-picks': 'true',
'show-elements': 'image',
'show-fields': 'all'
}
response = requests.get(api_url, params=payload)
def parse(self, response):
titles = response.selector.xpath("normalize-space(//title)")
for titles in titles:
body = response.xpath("//p").extract()
body2 = "".join(body)
print remove_tags(body2).encode('utf-8')
return titles
get_content()
代码运行时不会产生错误,但不会向 Python IDLE 打印任何内容。我怀疑这是因为我没有正确缩进某些内容。我尝试过使用缩进,但是我没有取得任何进展。这是我的问题还是我对这段代码做了完全错误的事情?
谢谢
最佳答案
尝试用 beautifulSoup 解析:
from bs4 import BeautifulSoup
api_url = 'http://beta.content.guardianapis.com/football/premierleague'
payload = {
'api-key': '',
'page-size': 10,
'show-editors-picks': 'true',
'show-elements': 'image',
'show-fields': 'all'
}
response = requests.get(api_url, params=payload).content
soup = BeautifulSoup(response)
text = [''.join(s.findAll(text=True))for s in soup.findAll('p')]
好的,这段代码应该正是您想要的:
from bs4 import BeautifulSoup
response = requests.get(api_url, params=payload).content
soup = BeautifulSoup(response)
text = [''.join(s.findAll(text=True)).encode("utf-8") for s in soup.findAll('p')]
for x in text:
print x
*Plenty of sides tried free-flowing, pacey Latin football this summer – even England had
their moments. A moment. But Argentina stayed functional. They haven’t conceded once in the knockouts, they’ve not been behind in any game, and they don’t mind a lack of respect. Coach Alejandro “The Sloth” Sabella says his side are “sore, beaten and tired after the war [with Holland]. But with work, humility and seriousness, we’ll get there”; Pablo Zabaleta says their strengths are spoiling, staying “compact and tight”, “closing down” and feeding on negativity. “Sometimes, if you have all the people against you, you feel even stronger.”
A series of heroic performances were undone by moments of cold quality – Switzerland, Mexico and Nigeria among those losing to cruel late strikes; and the USA stopped in extra time. But raw passion was at the heart of all the summer’s enduring images: Brazil’s maelstrom; Ivory Coast’s Serey Die in tears during his anthem; Suárez against England; Suárez against Chiellini; and the best squad meltdown for years – Ghana’s trip featuring a fist fight, suspensions, a plane load of cash and an inquiry. FA president Kwesi Nyantakyi: “We will unravel this farce.”
Van Gaal’s goalkeeper subbing move went down well: widely taken as evidence of brave, unsentimental, original thinking (even if Martin O’Neill did it first, in Leicester City’s 1996 play-off final) – and not as evidence of daft, look-at-me risk-taking, which it could have been if Tim Krul had gaffed. But the wider signs for Manchester United were good: a readiness to be flexible on tactics, to switch his back-line formation mid-game, to make space for flair, and to treat the press in a no-nonsense “je lot zijn idioten” way that’ll bring back warm pre-Moyes memories. He had no interest in the third-place play-off, and wasn’t shy to say so.
It’s a biennial revelation. The fundamentals of Germany’s 2002 football reboot are well-known - new academies with German quotas, leading to more German Bundesliga first-teamers at clubs where “50+1” ownership rules stop single entities from taking over. Joachim Löw was installed with a long-term brief, and will lead his team out in the final. England, in the same period, tried four different managers, giving each a smaller talent pool to pick from as the Premier League filled out with foreign owners and foreign players, gorged on its £5.5bn income, and grassroots facilities festered. Still, a Premier B League should fix it.
Bryan Ruiz, not good enough for Fulham’s relegation campaign and shipped out to make way for Kostas Mitroglou, captained Costa Rica into the knockout stage, scoring twice. He starred alongside Joel Campbell, who faces another season on loan from Arsenal. Also making points: Swiss Arsenal reject Johan Djourou; Colombia’s Pablo Armero, a loan flop at West Ham; Algeria pair Rafik Halliche (ex-Fulham) and Carl Medjani (ex-Liverpool); Mexico’s Spurs reject Giovani dos Santos; Germany’s Shkodran Mustafi, given a free by Everton in 2012; and former West Brom and Forest defender Gonzalo Jara, a star for Chile, despite a brutal own-goal/penalty miss double. Even Gervinho looked good.
The surprise on 2014’s top player lists so far: the number of keepers. There’s Tim Howard, whose old high school yearbook photo motto, “It will take a nation of millions to hold me back”, went viral; Costa Rica’s Keylor Navas, now in talks with Bayern Munich; Mexico’s free agent Guillermo Ochoa, whose Gordon Banks moment against Brazil put him in a good bargaining position; Nigeria’s Vincent Enyeama; Germany’s Manuel Neuer; Argentina’s Sergio Romero; and potentially Van Gaal’s strutting mind-gamer Tim Krul, who revelled in his cameo chance. Being a keeper is cool again. Even the ones who play for backwater minnows have their own Head & Shoulders ads.
Pre-tournament, DeAndre Yedlin was a Seattle Sounders homegrown full-back – low on European scouting lists, a known unknown. He’s now the answer to everyone’s full-back needs – his USMNTMVP game against Belgium drawing Roma, Liverpool, Inter, Genoa, Anderlecht and others. Club owner Adrian Hanauer says he doesn’t fancy selling Yedlin, but, on the other hand, “there’s always a number”. Among other talents who weren’t so well-known in inward-looking Premier League circles, where even Monaco’s €45m James Rodríguez counts as a breakthrough act: PSV’s winger Memphis Depay, Lille’s Divock Origi, about to join Liverpool, and Atlético Madrid’s José Giménez, whose buyout clause is on the rise.
Holland’s kicks were clinical against Costa Rica. Then, four days later, two players refused to take one and they lost 4-2. But science says it’s not a lottery. Among the historical World Cup data from analyst Robert O’Connor: the side kicking first win 60% of the time; players aged under 22 score 85% of their kicks, over-22s score 78%; keepers dive low and away from the centre of their net 94% of the time. Overall the ideal taker is young, left-footed, with a “well-established pre-shot routine” and wearing a red shirt. Today’s tailored facts: Argentina have won four out of five of their shootouts, Germany four out of four. One was against Argentina, in 2006.
For all the bad press, when something really bad happened – something disgusting – Fifa didn’t hold back. They fined Argentina £200,000 for breaching press conference regulations – failing to provide a player to give quotes “on three consecutive occasions”. Luis Suárez, meanwhile, was fined £96,000. But Suárez’s four-month ban did represent an unexpectedly heavy hit - a bit “fascist”, reckoned the Uruguay president José Mujica, who called it “an assault on the poor” driven by “Fifa’s bunch of old sons of bitches”. Meanwhile, Pepe was fined £10,000 for a headbutt, Alex Song £13,000 for an elbow chop, and Algeria £32,000 for fans using lasers, while none of the 12 complaints made about racist, homophobic or far-right chants or banners led to any Fifa action.
16 August Arsenal v Crystal Palace
16 August Burnley v Chelsea
16 August Leicester v Everton
16 August Liverpool v Southampton
16 August Man Utd v Swansea
etc...............*
关于python - HTML 清理代码不太有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24708097/
我需要为元素属性动态构建 XPath 查询,其中属性值由用户提供。我不确定如何清理或清理此值以防止 XPath 等同于 SQL 注入(inject)攻击。例如(在 PHP 中): xpath("//m
问题很简单:在使用 PHPmailer 类时我应该使用任何类型的清理吗? 我制作了使用 phpmailer 类发送电子邮件的简单发送邮件表单。目前我只使用“htmlspecialchars”进行清理(
你可以在python中创建一个在for循环退出时运行清理代码的迭代吗?就像是: from random import randint class Iterable: def __iter__(
假设我定期将数据插入 SQLite 数据库,然后清除前 50% 的数据,但我不清理。 我现在是否有类似文件前 50% 的清零页面之类的东西?如果我添加另一批数据,我是否正在填写那些清零的页面? 手册中
我有一堆 HTML 代码,我想在其中删除所有 HTML 标记。 我认为 Regex(正则表达式)可以做到这一点。通过搜索和替换,我将如何执行此操作? 我尝试了 ,我认为 * 是通配符,但显然不是。
我仍在学习 Haskell,我想知道是否有一种不太冗长的方法来使用 1 行代码来表达以下语句: map (\x -> (x, (if mod x 3 == 0 then "fizz" else "")
我需要怎么做才能正确清理/转义程序化SSH命令中输入的参数? 例如,路径参数- public boolean exists(String path) { try { Chann
这个问题已经有答案了: How to clear the canvas for redrawing (25 个回答) 已关闭10 个月前。 我目前正在尝试创建一个带有雨滴落下的 Canvas ,我唯一
我目前正在使用此过程来清理/过滤用户输入的评论 -> 这个是用来去掉斜线的……和 if (get_magic_quotes_gpc()) { function stripslashe
是否可以在 portal_setup 中删除旧的导入配置文件。 目前,我的网站上有许多可追溯到 2009 年的条目:: import-all-profile-Products.Archetypes_
假设我有多个指令,包括以下内容: ...template content... ...template content... 你如何销毁指令?通常我会在 jquery 中做一些我 $('#2').re
我正在开发一个可移植java应用程序,它可以在用户的PC(Windows XP)上动态生成一些文件。现在,我想要的是在java程序退出后删除这些临时文件。显然,java的文件删除机制是不可信的。即
我有一个 argv c 程序,它反转单词,并查看它是否是回文。我只是想清理输出并让它打印原始输入而不是相反的输入,但由于它是 argv,我似乎不知道该怎么做。 int main(int argc, c
我的网页上有一篇用 markdown 写的文章,我想在索引页上显示一份简短的简历。 问题是正文有markdown,我想在简历上显示纯文本。 例如: Article text: Hello people
在下面的代码片段中,可以做些什么来a)让编译器安静,b)清理交叉的指针困惑? extern struct tree *sintablein[sintablesize]; struct tree *(*
我试图弄清楚 WeakHashMap 在垃圾收集后如何清理。正如你们中许多人可能知道的那样,当 WeakHashMap 条目的键被垃圾回收时,它会自动删除。但是,例如,如果我做这样的事情: List>
我对构建的理解是,它只编译上次构建中编辑过的Java文件,而干净构建将删除所有类文件并重新编译所有文件。那么,当单独构建就足以满足我提供最新版本的类文件的需要时,干净构建的效用是什么? 最佳答案 有时
是否有任何简单的(内置的、附加的、开源的或商业的)在 Postgresql(主从)上进行复制,以便在复制时清理从属内部的数据以符合 PCI 合规性? ETL工具怎么样?它不一定是瞬时的……最多一个小时
我有一个将数据保存到 MySQL 数据库的网站 在将 HTML 插入 MySQL 或在我的网站上显示它时,我应该转义 HTML 吗? 理想情况下,我想将原始 HTML 输入到我的数据库中,并在每次从中
我知道我已经asked一个关于 sanitizer 和转义的问题,但我有一个问题没有得到回答。 好了,到此为止。如果我有一个 PHP 脚本并且我 GET用户输入和SELECT它来自 mySQL 数据库
我是一名优秀的程序员,十分优秀!