我的当地机场不光彩地阻止没有IE的用户,看起来很糟糕.我想编写一个Python脚本,每隔几分钟就可以获取Arrival和Departures页面的内容,并以更易读的方式显示它们.
我选择的工具是机械化欺骗网站以相信我使用IE,而BeautifulSoup用于解析页面以获取航班数据表.
老实说,我迷失在BeautifulSoup文档中,无法理解如何从整个文档中获取表(我知道他的标题),以及如何从该表中获取行列表.
有任何想法吗?
我想抓取一个网站,问题是,它充满了JavaScript的东西,比如按钮等,当按下它们时,它们不会改变URL,但页面上的数据会发生变化.
通常我使用LWP/Mechanize等来抓取网站,但都不支持JavaScript.任何的想法?
关于如何使用XML包中的readHTMLTable,我有很好的答案,我使用常规的http页面,但是我无法通过https页面解决我的问题.
我想在这个网站上阅读表格(网址字符串):
library(RTidyHTML)
library(XML)
url <- "https://ned.nih.gov/search/ViewDetails.aspx?NIHID=0010121048"
h = htmlParse(url)
tables <- readHTMLTable(url)
Run Code Online (Sandbox Code Playgroud)
但是我得到了这个错误:文件https://ned.nih.gov/search/Vi...does不存在.
我试图通过https问题(下面的前两行)(使用谷歌找到解决方案)(例如:http://tonybreyal.wordpress.com/2012/01/13/ra-quick-scrape-of -top-grossing-films-from-boxofficemojo-com /).
这个技巧有助于查看更多页面,但任何提取表的尝试都无法正常工作.任何建议表示赞赏 我需要组织,组织标题,经理等表格字段.
#attempt to get past the https problem
raw <- getURL(url, followlocation = TRUE, cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl"))
head(raw)
[1] "\r\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html;
...
h = htmlParse(raw)
Error in htmlParse(raw) : File ...
tables <- readHTMLTable(raw)
Error in htmlParse(doc) : File ...
Run Code Online (Sandbox Code Playgroud) 我正在观看一个使用Google Chrome和Fiddler 4.4版的网站.
该页面使用AJAX来更新其数据.我想阻止一个特定的URL来测试如果它不起作用会发生什么.
阻止URL的最简单方法是什么?
当我尝试使用Phantomjs 废弃此站点时,默认情况下,Phantomjs会将以下标头发送到服务器:
"name":"User-Agent",
"value":"Mozilla/5.0 (Unknown; Linux i686) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.9.1 Safari/534.34"}
Run Code Online (Sandbox Code Playgroud)
我得到了status 405 "Not Allowed"回应.
我在Phantomjs API Reference中读到,为了模仿来自其他浏览器的请求,我应该更改我的User-Agent值.在维基百科上,我找到了我应该用来假装在Ubuntu下的Firefox的价值:
'name': 'User-Agent',
'value': 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:16.0) Gecko/20120815 Firefox/16.0'
Run Code Online (Sandbox Code Playgroud)
我应该在Phantomjs的哪个部分放置这些属性?我应该在哪里插入它们 - 在page.open里面,或在page.evaluate里面,或者在它的顶部?
我试图从R中受密码保护的网站上抓取数据.看来,httr和RCurl软件包似乎是使用密码认证进行抓取的最佳选择(我也查看了XML包).
我试图抓取的网站如下(您需要一个免费帐户才能访问整个页面):http: //subscribers.footballguys.com/myfbg/myviewprojections.php ?projector = 2
这是我的两次尝试(用我的用户名替换"username",用我的密码替换"password"):
#This returns "Status: 200" without the data from the page:
library(httr)
GET("http://subscribers.footballguys.com/myfbg/myviewprojections.php?projector=2", authenticate("username", "password"))
#This returns the non-password protected preview (i.e., not the full page):
library(XML)
library(RCurl)
readHTMLTable(getURL("http://subscribers.footballguys.com/myfbg/myviewprojections.php?projector=2", userpwd = "username:password"))
Run Code Online (Sandbox Code Playgroud)
我查看了其他相关帖子(下面的链接),但无法弄清楚如何将他们的答案应用到我的案例中.
如何用R(https链接)webscrape安全页面(使用XML包中的readHTMLTable)?
http://www.inside-r.org/questions/how-scrape-data-password-protected-https-website-using-r-hold
在之前的问题中,其中一位作者aiohttp善意地建议使用以下新语法从aiohttp获取多个URL:async withPython 3.5
import aiohttp
import asyncio
async def fetch(session, url):
with aiohttp.Timeout(10):
async with session.get(url) as response:
return await response.text()
async def fetch_all(session, urls, loop):
results = await asyncio.wait([loop.create_task(fetch(session, url))
for url in urls])
return results
if __name__ == '__main__':
loop = asyncio.get_event_loop()
# breaks because of the first url
urls = ['http://SDFKHSKHGKLHSKLJHGSDFKSJH.com',
'http://google.com',
'http://twitter.com']
with aiohttp.ClientSession(loop=loop) as session:
the_results = loop.run_until_complete(
fetch_all(session, urls, loop))
# do something with the the_results
Run Code Online (Sandbox Code Playgroud)
但是,当其中一个session.get(url) …
我有
urls = ['url','url','url'...]
Run Code Online (Sandbox Code Playgroud)
这就是我正在做的事情
urls.map(async (url)=>{
await page.goto(`${url}`);
await page.waitForNavigation({ waitUntil: 'networkidle' });
})
Run Code Online (Sandbox Code Playgroud)
这似乎不等待页面加载并快速访问所有网址(我甚至尝试使用page.waitFor)
只是想知道我做了一些根本错误的事情,或者不建议/支持这种类型的功能
对于一个项目,我希望能够创建一个包含一些特定符号串的推文数据集.因为我还要去早的时间有可能,我尝试使用GetOldTweets脚本(https://github.com/Jefferson-Henrique/GetOldTweets-python这里提到):/sf/answers/2455454431/.
问题是,它无法提取包含符号作为输入的推文.实际上,人们甚至无法直接在Twitter上搜索包含所需符号的任何推文.
为了更清楚地解释问题,请考虑以下示例案例.我想提取包含字符串'!!!'的所有推文 在过去两年内.
最好的方法是什么(如果这是可行的)?
我有这个脚本在Python 3中制作:
response = simple_get("https://en.wikipedia.org/wiki/Mathematics")
result = {}
result["url"] = url
if response is not None:
html = BeautifulSoup(response, 'html.parser')
title = html.select("#firstHeading")[0].text
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,我可以从文章中获得标题,但我无法弄清楚如何从"数学(从希腊语μά..."到内容表中获取文本...
web-scraping ×10
python ×4
r ×2
xml ×2
aiohttp ×1
data-mining ×1
debugging ×1
fiddler ×1
html ×1
httr ×1
javascript ×1
perl ×1
phantomjs ×1
puppeteer ×1
python-3.x ×1
rcurl ×1
tabular ×1
twitter ×1
user-agent ×1
web-crawler ×1
wikipedia ×1